# StridedSlice

public final class **StridedSlice** Return a strided slice from \`input\`.


Note, most python users will want to use the Python [`Tensor.__getitem__`](https://www.tensorflow.org/api_docs/python/tf/Tensor#__getitem__)
or [`Variable.__getitem__`](https://www.tensorflow.org/api_docs/python/tf/Variable#__getitem__) rather than this op directly.


The goal of this op is to produce a new tensor with a subset of
the elements from the \`n\` dimensional \`input\` tensor. The subset is chosen using
a sequence of \`m\` sparse range specifications encoded into the arguments
of this function. Note, in some cases
\`m\` could be equal to \`n\`, but this need not be the case. Each
range specification entry can be one of the following:


- An ellipsis (...). Ellipses are used to imply zero or more
dimensions of full-dimension selection and are produced using
\`ellipsis_mask\`. For example, \`foo\[...\]\` is the identity slice.


- A new axis. This is used to insert a new shape=1 dimension and is
produced using \`new_axis_mask\`. For example, \`foo\[:, ...\]\` where
\`foo\` is shape \`(3, 4)\` produces a \`(1, 3, 4)\` tensor.


- A range \`begin:end:stride\`. This is used to specify how much to choose from
a given dimension. \`stride\` can be any integer but 0. \`begin\` is an integer
which represents the index of the first value to select while \`end\` represents
the index of the last value to select. The number of values selected in each
dimension is \`end - begin\` if \`stride \> 0\` and \`begin - end\` if \`stride \< 0\`.
\`begin\` and \`end\` can be negative where \`-1\` is the last element, \`-2\` is
the second to last. \`begin_mask\` controls whether to replace the explicitly
given \`begin\` with an implicit effective value of \`0\` if \`stride \> 0\` and
\`-1\` if \`stride \< 0\`. \`end_mask\` is analogous but produces the number
required to create the largest open interval. For example, given a shape
\`(3,)\` tensor \`foo\[:\]\`, the effective \`begin\` and \`end\` are \`0\` and \`3\`. Do
not assume this is equivalent to \`foo\[0:-1\]\` which has an effective \`begin\`
and \`end\` of \`0\` and \`2\`. Another example is \`foo\[-2::-1\]\` which reverses the
first dimension of a tensor while dropping the last two (in the original
order elements). For example \`foo = \[1,2,3,4\]; foo\[-2::-1\]\` is \`\[4,3\]\`.


- A single index. This is used to keep only elements that have a given
index. For example (\`foo\[2, :\]\` on a shape \`(5,6)\` tensor produces a
shape \`(6,)\` tensor. This is encoded in \`begin\` and \`end\` and
\`shrink_axis_mask\`.


Each conceptual range specification is encoded in the op's argument. This
encoding is best understand by considering a non-trivial example. In
particular,
\`foo\[1, 2:4, None, ..., :-3:-1, :\]\` will be encoded as

    begin = [1, 2, x, x, 0, x] # x denotes don't care (usually 0)
     end = [2, 4, x, x, -3, x]
     strides = [1, 1, x, x, -1, 1]
     begin_mask = 1&lt;&lt;4 | 1&lt;&lt;5 = 48
     end_mask = 1&lt;&lt;5 = 32
     ellipsis_mask = 1&lt;&lt;3 = 8
     new_axis_mask = 1&lt;&lt;2 = 4
     shrink_axis_mask = 1&lt;&lt;0 = 1
     
In this case if \`foo.shape\` is (5, 5, 5, 5, 5, 5) the final shape of the slice becomes (2, 1, 5, 5, 2, 5). Let us walk step by step through each argument specification.


1. The first argument in the example slice is turned into \`begin = 1\` and
\`end = begin + 1 = 2\`. To disambiguate from the original spec \`2:4\` we
also set the appropriate bit in \`shrink_axis_mask\`.


2. \`2:4\` is contributes 2, 4, 1 to begin, end, and stride. All masks have
zero bits contributed.


3. None is a synonym for [`tf.newaxis`](https://www.tensorflow.org/api_docs/python/tf#newaxis). This means insert a dimension of size 1
dimension in the final shape. Dummy values are contributed to begin,
end and stride, while the new_axis_mask bit is set.


4. \`...\` grab the full ranges from as many dimensions as needed to
fully specify a slice for every dimension of the input shape.


5. \`:-3:-1\` shows the use of negative indices. A negative index \`i\` associated
with a dimension that has shape \`s\` is converted to a positive index
\`s + i\`. So \`-1\` becomes \`s-1\` (i.e. the last element). This conversion
is done internally so begin, end and strides receive x, -3, and -1.
The appropriate begin_mask bit is set to indicate the start range is the
full range (ignoring the x).


6. \`:\` indicates that the entire contents of the corresponding dimension
is selected. This is equivalent to \`::\` or \`0::1\`. begin, end, and strides
receive 0, 0, and 1, respectively. The appropriate bits in \`begin_mask\` and
\`end_mask\` are also set.


*Requirements*:
\`0 != strides\[i\] for i in \[0, m)\`
\`ellipsis_mask must be a power of two (only one ellipsis)\`

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

### Nested Classes

|---|---|---|---|
| class | [StridedSlice.Options](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/core/StridedSlice.Options) || Optional attributes for `https://www.tensorflow.org/api_docs/java/org/tensorflow/op/core/StridedSlice` |

### Public Methods

|---|---|
| [Output](https://www.tensorflow.org/api_docs/java/org/tensorflow/Output)\<T\> | [asOutput](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/core/StridedSlice#asOutput())() Returns the symbolic handle of a tensor. |
| static [StridedSlice.Options](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/core/StridedSlice.Options) | [beginMask](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/core/StridedSlice#beginMask(java.lang.Long))(Long beginMask) |
| static \<T, U extends Number\> [StridedSlice](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/core/StridedSlice)\<T\> | [create](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/core/StridedSlice#create(org.tensorflow.op.Scope,%20org.tensorflow.Operand<T>,%20org.tensorflow.Operand<U>,%20org.tensorflow.Operand<U>,%20org.tensorflow.Operand<U>,%20org.tensorflow.op.core.StridedSlice.Options...))([Scope](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/Scope) scope, [Operand](https://www.tensorflow.org/api_docs/java/org/tensorflow/Operand)\<T\> input, [Operand](https://www.tensorflow.org/api_docs/java/org/tensorflow/Operand)\<U\> begin, [Operand](https://www.tensorflow.org/api_docs/java/org/tensorflow/Operand)\<U\> end, [Operand](https://www.tensorflow.org/api_docs/java/org/tensorflow/Operand)\<U\> strides, [Options...](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/core/StridedSlice.Options) options) Factory method to create a class wrapping a new StridedSlice operation. |
| static [StridedSlice.Options](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/core/StridedSlice.Options) | [ellipsisMask](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/core/StridedSlice#ellipsisMask(java.lang.Long))(Long ellipsisMask) |
| static [StridedSlice.Options](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/core/StridedSlice.Options) | [endMask](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/core/StridedSlice#endMask(java.lang.Long))(Long endMask) |
| static [StridedSlice.Options](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/core/StridedSlice.Options) | [newAxisMask](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/core/StridedSlice#newAxisMask(java.lang.Long))(Long newAxisMask) |
| [Output](https://www.tensorflow.org/api_docs/java/org/tensorflow/Output)\<T\> | [output](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/core/StridedSlice#output())() |
| static [StridedSlice.Options](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/core/StridedSlice.Options) | [shrinkAxisMask](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/core/StridedSlice#shrinkAxisMask(java.lang.Long))(Long shrinkAxisMask) |

### Inherited Methods

From class [org.tensorflow.op.PrimitiveOp](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/PrimitiveOp)

|---|---|
| final boolean | [equals](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/PrimitiveOp#equals(java.lang.Object))(Object obj) |
| final int | [hashCode](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/PrimitiveOp#hashCode())() |
| [Operation](https://www.tensorflow.org/api_docs/java/org/tensorflow/Operation) | [op](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/PrimitiveOp#op())() Returns the underlying `https://www.tensorflow.org/api_docs/java/org/tensorflow/Operation` |
| final String | [toString](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/PrimitiveOp#toString())() |

From class java.lang.Object

|---|---|
| boolean | equals(Object arg0) |
| final Class\<?\> | getClass() |
| int | hashCode() |
| final void | notify() |
| final void | notifyAll() |
| String | toString() |
| final void | wait(long arg0, int arg1) |
| final void | wait(long arg0) |
| final void | wait() |

From interface [org.tensorflow.Operand](https://www.tensorflow.org/api_docs/java/org/tensorflow/Operand)

|---|---|
| abstract [Output](https://www.tensorflow.org/api_docs/java/org/tensorflow/Output)\<T\> | [asOutput](https://www.tensorflow.org/api_docs/java/org/tensorflow/Operand#asOutput())() Returns the symbolic handle of a tensor. |

## Public Methods

#### public [Output](https://www.tensorflow.org/api_docs/java/org/tensorflow/Output)\<T\>
**asOutput**
()

Returns the symbolic handle of a tensor.

Inputs to TensorFlow operations are outputs of another TensorFlow operation. This method is
used to obtain a symbolic handle that represents the computation of the input.

<br />

#### public static [StridedSlice.Options](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/core/StridedSlice.Options)
**beginMask**
(Long beginMask)

<br />

##### Parameters

| beginMask | a bitmask where a bit i being 1 means to ignore the begin value and instead use the largest interval possible. At runtime begin\[i\] will be replaced with \`\[0, n-1)\` if \`stride\[i\] \> 0\` or \`\[-1, n-1\]\` if \`stride\[i\] \< 0\` |
|---|---|

#### public static [StridedSlice](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/core/StridedSlice)\<T\>
**create**
([Scope](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/Scope) scope, [Operand](https://www.tensorflow.org/api_docs/java/org/tensorflow/Operand)\<T\> input, [Operand](https://www.tensorflow.org/api_docs/java/org/tensorflow/Operand)\<U\> begin, [Operand](https://www.tensorflow.org/api_docs/java/org/tensorflow/Operand)\<U\> end, [Operand](https://www.tensorflow.org/api_docs/java/org/tensorflow/Operand)\<U\> strides, [Options...](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/core/StridedSlice.Options) options)

Factory method to create a class wrapping a new StridedSlice operation.

##### Parameters

| scope | current scope |
| begin | \`begin\[k\]\` specifies the offset into the \`k\`th range specification. The exact dimension this corresponds to will be determined by context. Out-of-bounds values will be silently clamped. If the \`k\`th bit of \`begin_mask\` then \`begin\[k\]\` is ignored and the full range of the appropriate dimension is used instead. Negative values causes indexing to start from the highest element e.g. If \`foo==\[1,2,3\]\` then \`foo\[-1\]==3\`. |
| end | \`end\[i\]\` is like \`begin\` with the exception that \`end_mask\` is used to determine full ranges. |
| strides | \`strides\[i\]\` specifies the increment in the \`i\`th specification after extracting a given element. Negative indices will reverse the original order. Out or range values are clamped to \`\[0,dim\[i\]) if slice\[i\]\>0\` or \`\[-1,dim\[i\]-1\] if slice\[i\] \< 0\` |
| options | carries optional attributes values |
|---|---|

##### Returns

- a new instance of StridedSlice

#### public static [StridedSlice.Options](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/core/StridedSlice.Options)
**ellipsisMask**
(Long ellipsisMask)

<br />

##### Parameters

| ellipsisMask | a bitmask where bit \`i\` being 1 means the \`i\`th position is actually an ellipsis. One bit at most can be 1. If \`ellipsis_mask == 0\`, then an implicit ellipsis mask of \`1 \<\< (m+1)\` is provided. This means that \`foo\[3:5\] == foo\[3:5, ...\]\`. An ellipsis implicitly creates as many range specifications as necessary to fully specify the sliced range for every dimension. For example for a 4-dimensional tensor \`foo\` the slice \`foo\[2, ..., 5:8\]\` implies \`foo\[2, :, :, 5:8\]\`. |
|---|---|

#### public static [StridedSlice.Options](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/core/StridedSlice.Options)
**endMask**
(Long endMask)

<br />

##### Parameters

| endMask | analogous to \`begin_mask\` |
|---|---|

#### public static [StridedSlice.Options](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/core/StridedSlice.Options)
**newAxisMask**
(Long newAxisMask)

<br />

##### Parameters

| newAxisMask | a bitmask where bit \`i\` being 1 means the \`i\`th specification creates a new shape 1 dimension. For example \`foo\[:4, tf.newaxis, :2\]\` would produce a shape \`(4, 1, 2)\` tensor. |
|---|---|

#### public [Output](https://www.tensorflow.org/api_docs/java/org/tensorflow/Output)\<T\>
**output**
()

<br />

#### public static [StridedSlice.Options](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/core/StridedSlice.Options)
**shrinkAxisMask**
(Long shrinkAxisMask)

<br />

##### Parameters

| shrinkAxisMask | a bitmask where bit \`i\` implies that the \`i\`th specification should shrink the dimensionality. begin and end must imply a slice of size 1 in the dimension. For example in python one might do \`foo\[:, 3, :\]\` which would result in \`shrink_axis_mask\` being 2. |
|---|---|