- java.lang.Object
-
- org.tensorflow.ndarray.index.Indices
-
-
Constructor Summary
Constructors Constructor Description Indices()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Indexall()An index that returns all elements of a dimension in the original order.static Indexat(long coord)A coordinate that selects a specific element on a given dimension.static Indexat(long coord, boolean keepDim)A coordinate that selects a specific element on a given dimension.static Indexat(NdArray<? extends Number> coord)A coordinate that selects a specific element on a given dimension.static Indexat(NdArray<? extends Number> coord, boolean keepDim)A coordinate that selects a specific element on a given dimension.static Indexellipsis()An index that expands to fill all available source dimensions.static Indexeven()An index that returns only elements found at an even position in the original dimension.static Indexflip()An index that returns only elements on a given dimension between two coordinates.static Indexhyperslab(long start, long stride, long count, long block)An index that returns elements according to an hyperslab defined bystart,stride,count,block.static IndexnewAxis()An index that inserts a new dimension of size 1 into the resulting array.static Indexodd()An index that returns only elements found at an odd position in the original dimension.static Indexrange(long start, long end)An index that returns only elements on a given dimension between two coordinates.static Indexseq(long... coords)An index that returns only specific elements on a given dimension.static Indexseq(NdArray<? extends Number> coords)An index that returns only specific elements on a given dimension.static Indexslice(long start, long end)An index that returns elements betweenstartandend.static Indexslice(long start, long end, long stride)An index that returns everystride-th element betweenstartandend.static Indexslice(Long start, Long end)An index that returns elements betweenstartandend.static Indexslice(Long start, Long end, long stride)An index that returns everystride-th element betweenstartandend.static IndexsliceFrom(long start)An index that returns only elements on a given dimension starting at a specific coordinate.static IndexsliceFrom(long start, long stride)An index that returns only elements on a given dimension starting at a specific coordinate, using the given stride.static IndexsliceTo(long end)An index that returns only elements on a given dimension up to a specific coordinate.static IndexsliceTo(long end, long stride)An index that returns only elements on a given dimension up to a specific coordinate, using the given stride.static Indexstep(long stride)An index that skips a fixed amount of coordinates between each values returned.
-
-
-
Method Detail
-
at
public static Index at(long coord)
A coordinate that selects a specific element on a given dimension.When this index is applied to a given dimension, the dimension is resolved as a single element and therefore is excluded from the computation of the rank.
For example, given a 3D matrix on the axis [x, y, z], if
matrix.slice(all(), at(0), at(0), then the rank of the returned slice is 1 and its number of elements isx.numElements()- Parameters:
coord- coordinate of the element on the indexed axis- Returns:
- index
-
at
public static Index at(NdArray<? extends Number> coord)
A coordinate that selects a specific element on a given dimension.This is equivalent to call
at(long)but where the value of the coordinate is provided by an N-dimensional array.- Parameters:
coord- scalar indicating the coordinate of the element on the indexed axis- Returns:
- index
- Throws:
IllegalRankException- ifcoordis not a scalar (rank 0)
-
at
public static Index at(long coord, boolean keepDim)
A coordinate that selects a specific element on a given dimension.When this index is applied to a given dimension, the dimension is resolved as a single element and therefore, if
keepDimis false, is excluded from the computation of the rank. If keepDim is true, the dimension is collapsed down to one element.For example, given a 3D matrix on the axis [x, y, z], if
matrix.slice(all(), at(0), at(0), then the rank of the returned slice is 1 and its number of elements isx.numElements()- Parameters:
coord- coordinate of the element on the indexed axiskeepDim- whether to remove the dimension.- Returns:
- index
-
at
public static Index at(NdArray<? extends Number> coord, boolean keepDim)
A coordinate that selects a specific element on a given dimension.This is equivalent to call
at(long, boolean)but where the value of the coordinate is provided by an N-dimensional array.If keepDim is true, the dimension is collapsed down to one element instead of being removed.
- Parameters:
coord- scalar indicating the coordinate of the element on the indexed axiskeepDim- whether to remove the dimension.- Returns:
- index
- Throws:
IllegalRankException- ifcoordis not a scalar (rank 0)
-
all
public static Index all()
An index that returns all elements of a dimension in the original order.Applying this index to a given dimension will return the original dimension directly.
For example, given a vector with
nelements,all()returns x0, x1, ..., xn-1- Returns:
- index
-
seq
public static Index seq(long... coords)
An index that returns only specific elements on a given dimension.For example, given a vector with
nelements on thexaxis, andn > 10,seq(8, 0, 3)returns x8, x0, x3- Parameters:
coords- coordinates of the elements in the sequence- Returns:
- index
-
seq
public static Index seq(NdArray<? extends Number> coords)
An index that returns only specific elements on a given dimension.This is equivalent to
seq(long...)but where the coordinates of the elements in the sequence are provided by an N-dimensional array.- Parameters:
coords- vector of coordinates of the elements in the sequence- Returns:
- index
- Throws:
IllegalRankException- ifcoordsis not a vector (rank 1)
-
even
public static Index even()
An index that returns only elements found at an even position in the original dimension.For example, given a vector with
nelements on thexaxis, and n is even,even()returns x0, x2, ..., xn-2- Returns:
- index
-
odd
public static Index odd()
An index that returns only elements found at an odd position in the original dimension.For example, given a vector with
nelements on thexaxis, and n is even,odd()returns x1, x3, ..., xn-1- Returns:
- index
-
step
public static Index step(long stride)
An index that skips a fixed amount of coordinates between each values returned.For example, given a vector with
nelements on thexaxis,step(k)returns x0, xk, xk*2, ...- Parameters:
stride- the number of elements between each steps- Returns:
- index
-
sliceFrom
public static Index sliceFrom(long start)
An index that returns only elements on a given dimension starting at a specific coordinate.For example, given a vector with
nelements on thexaxis, andn > k,from(k)returns xk, xk+1, ..., xn-1- Parameters:
start- coordinate of the first element of the sequence- Returns:
- index
-
sliceFrom
public static Index sliceFrom(long start, long stride)
An index that returns only elements on a given dimension starting at a specific coordinate, using the given stride.For example, given a vector with
nelements on thexaxis, andn > k,from(k)returns xk, xk+1, ..., xn-1- Parameters:
start- coordinate of the first element of the sequencestride- the stride to use- Returns:
- index
- See Also:
slice(long, long, long)
-
sliceTo
public static Index sliceTo(long end)
An index that returns only elements on a given dimension up to a specific coordinate.For example, given a vector with
nelements on thexaxis, andn > k,to(k)returns x0, x1, ..., xk- Parameters:
end- coordinate of the last element of the sequence (exclusive)- Returns:
- index
-
sliceTo
public static Index sliceTo(long end, long stride)
An index that returns only elements on a given dimension up to a specific coordinate, using the given stride.For example, given a vector with
nelements on thexaxis, andn > k,to(k)returns x0, x1, ..., xk- Parameters:
end- coordinate of the last element of the sequence (exclusive)stride- the stride to use- Returns:
- index
- See Also:
slice(long, long, long)
-
range
public static Index range(long start, long end)
An index that returns only elements on a given dimension between two coordinates.For example, given a vector with
nelements on thexaxis, andn > k > j,range(j, k)returns xj, xj+1, ..., xk- Parameters:
start- coordinate of the first element of the sequenceend- coordinate of the last element of the sequence (exclusive)- Returns:
- index
-
flip
public static Index flip()
An index that returns only elements on a given dimension between two coordinates.For example, given a vector with
nelements on thexaxis, andn > k > j,range(j, k)returns xj, xj+1, ..., xk- Returns:
- index
-
hyperslab
public static Index hyperslab(long start, long stride, long count, long block)
An index that returns elements according to an hyperslab defined bystart,stride,count,block. SeeHyperslab.- Parameters:
start- Starting location for the hyperslab.stride- The number of elements to separate each element or block to be selected.count- The number of elements or blocks to select along the dimension.block- The size of the block selected from the dimension.- Returns:
- index
-
newAxis
public static Index newAxis()
An index that inserts a new dimension of size 1 into the resulting array.- Returns:
- index
-
ellipsis
public static Index ellipsis()
An index that expands to fill all available source dimensions. Works the same as Python's....- Returns:
- index
-
slice
public static Index slice(long start, long end)
An index that returns elements betweenstartandend. Ifstartorendisnull, starts or ends at the beginning or the end, respectively.Analogous to Python's
:slice syntax.- Returns:
- index
-
slice
public static Index slice(long start, long end, long stride)
An index that returns everystride-th element betweenstartandend. Ifstartorendisnull, starts or ends at the beginning or the end, respectively.Analogous to Python's
:slice syntax.- Returns:
- index
-
slice
public static Index slice(Long start, Long end)
An index that returns elements betweenstartandend. Ifstartorendisnull, starts or ends at the beginning or the end, respectively.Analogous to Python's
:slice syntax.- Returns:
- index
-
-