org.nd4j.linalg.util

## Class NDArrayMath

• ```public class NDArrayMath
extends Object```
Author:
• ### Method Summary

All Methods
Modifier and Type Method and Description
`static long` `lengthPerSlice(INDArray arr)`
Return the length of a slice
`static long` ```lengthPerSlice(INDArray arr, int... dimension)```
The number of elements in a slice along a set of dimensions
`static int` ```mapIndexOntoTensor(int index, INDArray arr, int... rank)```
This maps an index of a vector on to a vector in the matrix that can be used for indexing in to a tensor
`static long` ```mapIndexOntoVector(int index, INDArray arr)```
This maps an index of a vector on to a vector in the matrix that can be used for indexing in to a tensor
`static long` `matricesPerSlice(INDArray arr)`
The number of vectors in each slice of an ndarray.
`static long` `numVectors(INDArray arr)`
Return the number of vectors for an array the number of vectors for an array
`static long` ```offsetForSlice(INDArray arr, int slice)```
Compute the offset for a given slice
`static long` ```sliceOffsetForTensor(int index, INDArray arr, int[] tensorShape)```
calculates the offset for a tensor
`static long` ```sliceOffsetForTensor(int index, INDArray arr, long[] tensorShape)```
`static long` ```tensorsPerSlice(INDArray arr, int[] tensorShape)```
Computes the tensors per slice given a tensor shape and array
`static long` `vectorsPerSlice(INDArray arr)`
The number of vectors in each slice of an ndarray.
`static long` ```vectorsPerSlice(INDArray arr, int... rank)```
The number of vectors in each slice of an ndarray.
• ### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`
• ### Method Detail

• #### offsetForSlice

```public static long offsetForSlice(INDArray arr,
int slice)```
Compute the offset for a given slice
Parameters:
`arr` - the array to compute the offset frm
`slice` - the slice to compute the offset for
Returns:
the offset for a given slice
• #### lengthPerSlice

```public static long lengthPerSlice(INDArray arr,
int... dimension)```
The number of elements in a slice along a set of dimensions
Parameters:
`arr` - the array to calculate the length per slice for
`dimension` - the dimensions to do the calculations along
Returns:
the number of elements in a slice along arbitrary dimensions
• #### lengthPerSlice

`public static long lengthPerSlice(INDArray arr)`
Return the length of a slice
Parameters:
`arr` - the array to get the length of a slice for
Returns:
the number of elements per slice in an array
• #### numVectors

`public static long numVectors(INDArray arr)`
Return the number of vectors for an array the number of vectors for an array
Parameters:
`arr` - the array to calculate the number of vectors for
Returns:
the number of vectors for the given array
• #### vectorsPerSlice

`public static long vectorsPerSlice(INDArray arr)`
The number of vectors in each slice of an ndarray.
Parameters:
`arr` - the array to get the number of vectors per slice for
Returns:
the number of vectors per slice
• #### tensorsPerSlice

```public static long tensorsPerSlice(INDArray arr,
int[] tensorShape)```
Computes the tensors per slice given a tensor shape and array
Parameters:
`arr` - the array to get the tensors per slice for
`tensorShape` - the desired tensor shape
Returns:
the tensors per slice of an ndarray
• #### matricesPerSlice

`public static long matricesPerSlice(INDArray arr)`
The number of vectors in each slice of an ndarray.
Parameters:
`arr` - the array to get the number of vectors per slice for
Returns:
the number of vectors per slice
• #### vectorsPerSlice

```public static long vectorsPerSlice(INDArray arr,
int... rank)```
The number of vectors in each slice of an ndarray.
Parameters:
`arr` - the array to get the number of vectors per slice for
`rank` - the dimensions to get the number of vectors per slice for
Returns:
the number of vectors per slice
• #### sliceOffsetForTensor

```public static long sliceOffsetForTensor(int index,
INDArray arr,
int[] tensorShape)```
calculates the offset for a tensor
Parameters:
`index` -
`arr` -
`tensorShape` -
Returns:
• #### sliceOffsetForTensor

```public static long sliceOffsetForTensor(int index,
INDArray arr,
long[] tensorShape)```
• #### mapIndexOntoTensor

```public static int mapIndexOntoTensor(int index,
INDArray arr,
int... rank)```
This maps an index of a vector on to a vector in the matrix that can be used for indexing in to a tensor
Parameters:
`index` - the index to map
`arr` - the array to use for indexing
`rank` - the dimensions to compute a slice for
Returns:
the mapped index
• #### mapIndexOntoVector

```public static long mapIndexOntoVector(int index,
INDArray arr)```
This maps an index of a vector on to a vector in the matrix that can be used for indexing in to a tensor
Parameters:
`index` - the index to map
`arr` - the array to use for indexing
Returns:
the mapped index