strided_slice¶
- paddle.fluid.layers.nn. strided_slice ( input, axes, starts, ends, strides ) [source]
- 
         - Alias_main
- 
           paddle.strided_slice :alias: paddle.strided_slice,paddle.tensor.strided_slice,paddle.tensor.manipulation.strided_slice :old_api: paddle.fluid.layers.strided_slice 
 This operator produces a slice of inputalong multiple axes. Similar to numpy: https://docs.scipy.org/doc/numpy/reference/arrays.indexing.html Slice usesaxes,startsandendsattributes to specify the start and end dimension for each axis in the list of axes and Slice uses this information to slice the input data tensor. If a negative value is passed tostartsorendssuch as \(-i\), it represents the reverse position of the axis \(i-1\) th(here 0 is the initial position). Thestridesrepresents steps of slicing and if thestridesis negative, slice operation is in the opposite direction. If the value passed tostartsorendsis greater than n (the number of elements in this dimension), it represents n. For slicing to the end of a dimension with unknown size, it is recommended to pass in INT_MAX. The size ofaxesmust be equal tostarts,endsandstrides. Following examples will explain how strided_slice works:Case1: Given: data = [ [1, 2, 3, 4], [5, 6, 7, 8], ] axes = [0, 1] starts = [1, 0] ends = [2, 3] strides = [1, 1] Then: result = [ [5, 6, 7], ] Case2: Given: data = [ [1, 2, 3, 4], [5, 6, 7, 8], ] axes = [0, 1] starts = [0, 1] ends = [2, 0] strides = [1, -1] Then: result = [ [8, 7, 6], ] Case3: Given: data = [ [1, 2, 3, 4], [5, 6, 7, 8], ] axes = [0, 1] starts = [0, 1] ends = [-1, 1000] strides = [1, 3] Then: result = [ [2], ]- Parameters
- 
           - input (Variable) – An N-D - Tensoror- LoDTensor. The data type is- bool,- float32,- float64,- int32or- int64.
- axes (list|tuple) – The data type is - int32. Axes that starts and ends apply to. It’s optional. If it is not provides, it will be treated as \([0,1,...,len(starts)-1]\).
- starts (list|tuple|Variable) – The data type is - int32. If- startsis a list or tuple, the elements of it should be integers or Tensors with shape [1]. If- startsis an Variable, it should be an 1-D Tensor. It represents starting indices of corresponding axis in- axes.
- ends (list|tuple|Variable) – The data type is - int32. If- endsis a list or tuple, the elements of it should be integers or Tensors with shape [1]. If- endsis an Variable, it should be an 1-D Tensor . It represents ending indices of corresponding axis in- axes.
- strides (list|tuple|Variable) – The data type is - int32. If- stridesis a list or tuple, the elements of it should be integers or Tensors with shape [1]. If- stridesis an Variable, it should be an 1-D Tensor . It represents slice step of corresponding axis in- axes.
 
- Returns
- 
           A TensororLoDTensorwith the same dimension asinput. The data type is same asinput.
- Return type
- 
           Variable 
- Raises
- 
           - TypeError – The type of - startsmust be list, tuple or Variable.
- TypeError – The type of - endsmust be list, tuple or Variable.
- TypeError – The type of - stridesmust be list, tuple or Variable.
 
 Examples import paddle.fluid as fluid import paddle paddle.enable_static() input = fluid.data( name="input", shape=[3, 4, 5, 6], dtype='float32') # example 1: # attr starts is a list which doesn't contain tensor Variable. axes = [0, 1, 2] starts = [-3, 0, 2] ends = [3, 2, 4] strides_1 = [1, 1, 1] strides_2 = [1, 1, 2] sliced_1 = fluid.layers.strided_slice(input, axes=axes, starts=starts, ends=ends, strides=strides_1) # sliced_1 is input[:, 0:3:1, 0:2:1, 2:4:1]. # example 2: # attr starts is a list which contain tensor Variable. minus_3 = fluid.layers.fill_constant([1], "int32", -3) sliced_2 = fluid.layers.strided_slice(input, axes=axes, starts=[minus_3, 0, 2], ends=ends, strides=strides_2) # sliced_2 is input[:, 0:3:1, 0:2:1, 2:4:2]. 
