# BaseOps

These ops are generally available directly on

`SameDiff`

instances. Due to an oversight before the release, this ops aren't also available on `Nd4j`

. To use the `INDArray`

variants of these operations, you will have to instantiate a `NDBase`

instance.INDArray all(INDArray x, int[] dimensions)

SDVariable all(SDVariable x, int[] dimensions)

SDVariable all(String name, SDVariable x, int[] dimensions)

Boolean and array reduction operation, optionally along specified dimensions

**x**(NDARRAY) - Input variable**dimensions**- Dimensions to reduce over. If dimensions are not specified, full array reduction is performed (Size: AtLeast(min=0))

INDArray any(INDArray x, int[] dimensions)

SDVariable any(SDVariable x, int[] dimensions)

SDVariable any(String name, SDVariable x, int[] dimensions)

Boolean or array reduction operation, optionally along specified dimensions

**x**(NDARRAY) - Input variable**dimensions**- Dimensions to reduce over. If dimensions are not specified, full array reduction is performed (Size: AtLeast(min=0))

INDArray argmax(INDArray in, boolean keepDims, int[] dimensions)

INDArray argmax(INDArray in, int[] dimensions)

SDVariable argmax(SDVariable in, boolean keepDims, int[] dimensions)

SDVariable argmax(SDVariable in, int[] dimensions)

SDVariable argmax(String name, SDVariable in, boolean keepDims, int[] dimensions)

SDVariable argmax(String name, SDVariable in, int[] dimensions)

Argmax array reduction operation, optionally along specified dimensions.

Output values are the index of the maximum value of each slice along the specified dimension.

Note that if keepDims = true, the output variable has the same rank as the input variable,

with the reduced dimensions having size 1. This can be useful for later broadcast operations (such as subtracting

the mean along a dimension).

Example: if input has shape [a,b,c] and dimensions=[1] then output has shape:

keepDims = true: [a,1,c]

keepDims = false: [a,c]

**in**(NUMERIC) - Input variable**keepDims**- If true: keep the dimensions that are reduced on (as size 1). False: remove the reduction dimensions - default = false**dimensions**- Dimensions to reduce over. If dimensions are not specified, full array reduction is performed (Size: AtLeast(min=0))

INDArray argmin(INDArray in, boolean keepDims, int[] dimensions)

INDArray argmin(INDArray in, int[] dimensions)

SDVariable argmin(SDVariable in, boolean keepDims, int[] dimensions)

SDVariable argmin(SDVariable in, int[] dimensions)

SDVariable argmin(String name, SDVariable in, boolean keepDims, int[] dimensions)

SDVariable argmin(String name, SDVariable in, int[] dimensions)

Argmin array reduction operation, optionally along specified dimensions.

Output values are the index of the minimum value of each slice along the specified dimension.

Note that if keepDims = true, the output variable has the same rank as the input variable,

with the reduced dimensions having size 1. This can be useful for later broadcast operations (such as subtracting

the mean along a dimension).

Example: if input has shape [a,b,c] and dimensions=[1] then output has shape:

keepDims = true: [a,1,c]

keepDims = false: [a,c]

Note: supports broadcasting if x and y have different shapes and are broadcastable.

For example, if X has shape [1,10] and Y has shape [5,10] then op(X,Y) has output shape [5,10]

Broadcast rules are the same as NumPy: https://docs.scipy.org/doc/numpy/user/basics.broadcasting.html

**in**(NUMERIC) - Input variable**keepDims**- If true: keep the dimensions that are reduced on (as size 1). False: remove the reduction dimensions - default = false**dimensions**- Dimensions to reduce over. If dimensions are not specified, full array reduction is performed (Size: AtLeast(min=0))

INDArray batchMmul(INDArray inputsA, INDArray inputsB, boolean transposeA, boolean transposeB)

INDArray batchMmul(INDArray inputsA, INDArray inputsB)

SDVariable batchMmul(SDVariable inputsA, SDVariable inputsB, boolean transposeA, boolean transposeB)

SDVariable batchMmul(SDVariable inputsA, SDVariable inputsB)

SDVariable batchMmul(String name, SDVariable inputsA, SDVariable inputsB, boolean transposeA, boolean transposeB)

SDVariable batchMmul(String name, SDVariable inputsA, SDVariable inputsB)

Matrix multiply a batch of matrices. matricesA and matricesB have to be arrays of same

length and each pair taken from these sets has to have dimensions (M, N) and (N, K),

respectively. If transposeA is true, matrices from matricesA will have shape (N, M) instead.

Likewise, if transposeB is true, matrices from matricesB will have shape (K, N).

The result of this operation will be a batch of multiplied matrices. The

result has the same length as both input batches and each output matrix is of shape (M, K).

**inputsA**(NUMERIC) - First array of input matrices, all of shape (M, N) or (N, M)**inputsB**(NUMERIC) - Second array of input matrices, all of shape (N, K) or (K, N)**transposeA**- Whether to transpose A arrays or not - default = false**transposeB**- Whether to transpose B arrays or not - default = false

INDArray castTo(INDArray arg, DataType datatype)

SDVariable castTo(SDVariable arg, DataType datatype)

SDVariable castTo(String name, SDVariable arg, DataType datatype)

Cast the array to a new datatype - for example, Integer -> Float

**arg**(NDARRAY) - Input variable to cast**datatype**- Datatype to cast to

INDArray concat(INDArray inputs, int dimension)

SDVariable concat(SDVariable inputs, int dimension)

SDVariable concat(String name, SDVariable inputs, int dimension)

Concatenate a set of inputs along the specified dimension.

Note that inputs must have identical rank and identical dimensions, other than the dimension to stack on.

For example, if 2 inputs have shape [a, x, c] and [a, y, c] and dimension = 1, then the output has shape [a, x+y, c]

**inputs**(NUMERIC) - Input variables**dimension**- Dimension to concatenate on

INDArray cumprod(INDArray in, boolean exclusive, boolean reverse, int[] axis)

INDArray cumprod(INDArray in, int[] axis)

SDVariable cumprod(SDVariable in, boolean exclusive, boolean reverse, int[] axis)

SDVariable cumprod(SDVariable in, int[] axis)

SDVariable cumprod(String name, SDVariable in, boolean exclusive, boolean reverse, int[] axis)

SDVariable cumprod(String name, SDVariable in, int[] axis)

Cumulative product operation.

For input: [ a, b, c], output is:

exclusive=false, reverse=false: [a, a

*b, a*b*c]exclusive=true, reverse=false, [0, a, a*b]

exclusive=false, reverse=true: [a

*b*c, b*c, c]exclusive=true, reverse=true: [b*c, c, 0]

**in**(NUMERIC) - Input variable**exclusive**- If true: exclude the first value - default = false**reverse**- If true: reverse the direction of the accumulation - default = false**axis**- Scalar axis argument for dimension to perform cumululative sum operations along (Size: AtLeast(min=1))

INDArray cumsum(INDArray in, boolean exclusive, boolean reverse, int[] axis)

INDArray cumsum(INDArray in, int[] axis)

SDVariable cumsum(SDVariable in, boolean exclusive, boolean reverse, int[] axis)

SDVariable cumsum(SDVariable in, int[] axis)

SDVariable cumsum(String name, SDVariable in, boolean exclusive, boolean reverse, int[] axis)

SDVariable cumsum(String name, SDVariable in, int[] axis)

Cumulative sum operation.

For input: [ a, b, c], output is:

exclusive=false, reverse=false: [a, a+b, a+b+c]

exclusive=true, reverse=false, [0, a, a+b]

exclusive=false, reverse=true: [a+b+c, b+c, c]

exclusive=true, reverse=true: [b+c, c, 0]

**in**(NUMERIC) - Input variable**exclusive**- If true: exclude the first value - default = false**reverse**- If true: reverse the direction of the accumulation - default = false**axis**- Scalar axis argument for dimension to perform cumululative sum operations along (Size: AtLeast(min=1))

INDArray dot(INDArray x, INDArray y, int[] dimensions)

SDVariable dot(SDVariable x, SDVariable y, int[] dimensions)

SDVariable dot(String name, SDVariable x, SDVariable y, int[] dimensions)

Pairwise dot product reduction along dimension

output = sum(i=0 ... size(dim)-1) x[i] * y[i]

**x**(NUMERIC) - first input**y**(NUMERIC) - second input**dimensions**- Dimensions to reduce over. If dimensions are not specified, full array reduction is performed (Size: AtLeast(min=0))

INDArray dynamicPartition(INDArray x, INDArray partitions, int numPartitions)

SDVariable dynamicPartition(SDVariable x, SDVariable partitions, int numPartitions)

SDVariable dynamicPartition(String name, SDVariable x, SDVariable partitions, int numPartitions)

Dynamically partition the input variable values into the specified number of paritions, using the indices.

Example:

input = [1,2,3,4,5]

numPartitions = 2

partitions = [1,0,0,1,0]

out[0] = [2,3,5]

out[1] = [1,4] `

**x**(NUMERIC) - Input variable**partitions**(INT) - 1D input with values 0 to numPartitions-1**numPartitions**- Number of partitions, >= 1

INDArray dynamicStitch(INDArray indices, INDArray x)

SDVariable dynamicStitch(SDVariable indices, SDVariable x)

SDVariable dynamicStitch(String name, SDVariable indices, SDVariable x)

Dynamically merge the specified input arrays into a single array, using the specified indices

**indices**(INT) - Indices to use when merging. Must be >= 1, same length as input variables**x**(NUMERIC) - Input variables.

INDArray eq(INDArray x, double y)

SDVariable eq(SDVariable x, double y)

SDVariable eq(String name, SDVariable x, double y)

Equals operation: elementwise x == y

Return boolean array with values true where satisfied, or false otherwise.

**x**(NUMERIC) - Input array**y**- Double value argument to use in operation

INDArray eq(INDArray x, INDArray y)

SDVariable eq(SDVariable x, SDVariable y)

SDVariable eq(String name, SDVariable x, SDVariable y)

Equal to operation: elementwise x == y

If x and y arrays have equal shape, the output shape is the same as these inputs.

Note: supports broadcasting if x and y have different shapes and are broadcastable.

For example, if X has shape [1,10] and Y has shape [5,10] then op(X,Y) has output shape [5,10]

Broadcast rules are the same as NumPy: https://docs.scipy.org/doc/numpy/user/basics.broadcasting.html

Return boolean array with values true where satisfied, or false otherwise.

**x**(NUMERIC) - Input 1**y**(NUMERIC) - Input 2

INDArray expandDims(INDArray x, int axis)

SDVariable expandDims(SDVariable x, int axis)

SDVariable expandDims(String name, SDVariable x, int axis)

Reshape the input by adding a 1 at the specified location.

For example, if input has shape [a, b], then output shape is:

axis = 0: [1, a, b]

axis = 1: [a, 1, b]

axis = 2: [a, b, 1]

**x**(NDARRAY) - Input variable**axis**- Axis to expand

INDArray fill(INDArray shape, DataType dataType, double value)

SDVariable fill(SDVariable shape, DataType dataType, double value)

SDVariable fill(String name, SDVariable shape, DataType dataType, double value)

Generate an output variable with the specified (dynamic) shape with all elements set to the specified value

**shape**(INT) - Shape: must be a 1D array/variable**dataType**- Datatype of the output array**value**- Value to set all elements to

INDArray gather(INDArray df, int[] indices, int axis)

SDVariable gather(SDVariable df, int[] indices, int axis)

SDVariable gather(String name, SDVariable df, int[] indices, int axis)

Gather slices from the input variable where the indices are specified as fixed int[] values.

Output shape is same as input shape, except for axis dimension, which has size equal to indices.length.

**df**(NUMERIC) - Input variable**indices**- Indices to get (Size: AtLeast(min=1))**axis**- Axis that the indices refer to

INDArray gather(INDArray df, INDArray indices, int axis)

SDVariable gather(SDVariable df, SDVariable indices, int axis)

SDVariable gather(String name, SDVariable df, SDVariable indices, int axis)

Gather slices from the input variable where the indices are specified as dynamic array values.

Output shape is same as input shape, except for axis dimension, which has size equal to indices.length.

**df**(NUMERIC) - Input variable**indices**(INT) - Indices to get slices for. Rank 0 or 1 input**axis**- Axis that the indices refer to

INDArray gatherNd(INDArray df, INDArray indices)

SDVariable gatherNd(SDVariable df, SDVariable indices)

SDVariable gatherNd(String name, SDVariable df, SDVariable indices)

Gather slices from df with shape specified by indices.

**df**(NUMERIC) -**indices**(NUMERIC) -

INDArray gt(INDArray x, double y)

SDVariable gt(SDVariable x, double y)

SDVariable gt(String name, SDVariable x, double y)

Greater than operation: elementwise x > y

Return boolean array with values true where satisfied, or false otherwise.

**x**(NUMERIC) - Input array**y**- Double value argument to use in operation

INDArray gt(INDArray x, INDArray y)

SDVariable gt(SDVariable x, SDVariable y)

SDVariable gt(String name, SDVariable x, SDVariable y)

Greater than operation: elementwise x > y

If x and y arrays have equal shape, the output shape is the same as these inputs.

Note: supports broadcasting if x and y have different shapes and are broadcastable.

For example, if X has shape [1,10] and Y has shape [5,10] then op(X,Y) has output shape [5,10]

Broadcast rules are the same as NumPy: https://docs.scipy.org/doc/numpy/user/basics.broadcasting.html

Return boolean array with values true where satisfied, or false otherwise.

**x**(NUMERIC) - Input 1**y**(NUMERIC) - Input 2

INDArray gte(INDArray x, double y)

SDVariable gte(SDVariable x, double y)

SDVariable gte(String name, SDVariable x, double y)

Greater than or equals operation: elementwise x >= y

Return boolean array with values true where satisfied, or false otherwise.

**x**(NUMERIC) - Input array**y**- Double value argument to use in operation

INDArray gte(INDArray x, INDArray y)

SDVariable gte(SDVariable x, SDVariable y)

SDVariable gte(String name, SDVariable x, SDVariable y)

Greater than or equal to operation: elementwise x >= y

If x and y arrays have equal shape, the output shape is the same as these inputs.

Note: supports broadcasting if x and y have different shapes and are broadcastable.

For example, if X has shape [1,10] and Y has shape [5,10] then op(X,Y) has output shape [5,10]

Return boolean array with values true where satisfied, or false otherwise.

**x**(NUMERIC) - Input 1**y**(NUMERIC) - Input 2

INDArray identity(INDArray input)

SDVariable identity(SDVariable input)

SDVariable identity(String name, SDVariable input)

Elementwise identity operation: out = x

**input**(NUMERIC) - Input variable

INDArray invertPermutation(INDArray input)

SDVariable invertPermutation(SDVariable input)

SDVariable invertPermutation(String name, SDVariable input)

Compute the inverse permutation indices for a permutation operation

Example: if input is [2, 0, 1] then output is [1, 2, 0]

The idea is that x.permute(input).permute(invertPermutation(input)) == x

**input**(INT) - 1D indices for permutation

INDArray isNumericTensor(INDArray x)

SDVariable isNumericTensor(SDVariable x)

SDVariable isNumericTensor(String name, SDVariable x)

Is the director a numeric tensor? In the current version of ND4J/SameDiff, this always returns true/1

**x**(NUMERIC) - Input variable

INDArray linspace(DataType dataType, double start, double stop, long number)

SDVariable linspace(DataType dataType, double start, double stop, long number)

SDVariable linspace(String name, DataType dataType, double start, double stop, long number)

Create a new 1d array with values evenly spaced between values 'start' and 'stop'

For example, linspace(start=3.0, stop=4.0, number=3) will generate [3.0, 3.5, 4.0]

**dataType**- Data type of the output array**start**- Start value**stop**- Stop value**number**- Number of values to generate

INDArray linspace(INDArray start, INDArray stop, INDArray number, DataType dataType)

SDVariable linspace(SDVariable start, SDVariable stop, SDVariable number, DataType dataType)

SDVariable linspace(String name, SDVariable start, SDVariable stop, SDVariable number, DataType dataType)

Create a new 1d array with values evenly spaced between values 'start' and 'stop'

For example, linspace(start=3.0, stop=4.0, number=3) will generate [3.0, 3.5, 4.0]

**start**(NUMERIC) - Start value**stop**(NUMERIC) - Stop value**number**(LONG) - Number of values to generate**dataType**- Data type of the output array

INDArray lt(INDArray x, double y)

SDVariable lt(SDVariable x, double y)

SDVariable lt(String name, SDVariable x, double y)

Less than operation: elementwise x < y

Return boolean array with values true where satisfied, or false otherwise.

**x**(NUMERIC) - Input array**y**- Double value argument to use in operation

INDArray lt(INDArray x, INDArray y)

SDVariable lt(SDVariable x, SDVariable y)

SDVariable lt(String name, SDVariable x, SDVariable y)

Less than operation: elementwise x < y

If x and y arrays have equal shape, the output shape is the same as these inputs.

Note: supports broadcasting if x and y have different shapes and are broadcastable.

For example, if X has shape [1,10] and Y has shape [5,10] then op(X,Y) has output shape [5,10]

Return boolean array with values true where satisfied, or false otherwise.

**x**(NUMERIC) - Input 1**y**(NUMERIC) - Input 2

INDArray lte(INDArray x, double y)

SDVariable lte(SDVariable x, double y)

SDVariable lte(String name, SDVariable x, double y)

Less than or equals operation: elementwise x <= y

Return boolean array with values true where satisfied, or false otherwise.

**x**(NUMERIC) - Input array**y**- Double value argument to use in operation

INDArray lte(INDArray x, INDArray y)

SDVariable lte(SDVariable x, SDVariable y)

SDVariable lte(String name, SDVariable x, SDVariable y)

Less than or equal to operation: elementwise x <= y

If x and y arrays have equal shape, the output shape is the same as these inputs.

Note: supports broadcasting if x and y have different shapes and are broadcastable.

For example, if X has shape [1,10] and Y has shape [5,10] then op(X,Y) has output shape [5,10]

Return boolean array with values true where satisfied, or false otherwise.

**x**(NUMERIC) - Input 1**y**(NUMERIC) - Input 2

INDArray matchCondition(INDArray in, Condition condition)

SDVariable matchCondition(SDVariable in, Condition condition)

SDVariable matchCondition(String name, SDVariable in, Condition condition)

Returns a boolean mask of equal shape to the input, where the condition is satisfied - value 1 where satisfied, 0 otherwise

**in**(NUMERIC) - Input**condition**- Condition

INDArray matchConditionCount(INDArray in, Condition condition)

SDVariable matchConditionCount(SDVariable in, Condition condition)

SDVariable matchConditionCount(String name, SDVariable in, Condition condition)

Returns a count of the number of elements that satisfy the condition

**in**(NUMERIC) - Input**condition**- Condition

INDArray matchConditionCount(INDArray in, Condition condition, boolean keepDim, int[] dimensions)

INDArray matchConditionCount(INDArray in, Condition condition, int[] dimensions)

SDVariable matchConditionCount(SDVariable in, Condition condition, boolean keepDim, int[] dimensions)

SDVariable matchConditionCount(SDVariable in, Condition condition, int[] dimensions)

SDVariable matchConditionCount(String name, SDVariable in, Condition condition, boolean keepDim, int[] dimensions)

SDVariable matchConditionCount(String name, SDVariable in, Condition condition, int[] dimensions)

Returns a count of the number of elements that satisfy the condition (for each slice along the specified dimensions)

Note that if keepDims = true, the output variable has the same rank as the input variable,

with the reduced dimensions having size 1. This can be useful for later broadcast operations (such as subtracting

the mean along a dimension).

Example: if input has shape [a,b,c] and dimensions=[1] then output has shape:

keepDims = true: [a,1,c]

keepDims = false: [a,c]

**in**(NUMERIC) - Input variable**condition**- Condition**keepDim**- If true: keep the dimensions that are reduced on (as size 1). False: remove the reduction dimensions - default = false**dimensions**- Dimensions to reduce over. If dimensions are not specified, full array reduction is performed (Size: AtLeast(min=0))

INDArray max(INDArray x, boolean keepDims, int[] dimensions)

INDArray max(INDArray x, int[] dimensions)

SDVariable max(SDVariable x, boolean keepDims, int[] dimensions)

SDVariable max(SDVariable x, int[] dimensions)

SDVariable max(String name, SDVariable x, boolean keepDims, int[] dimensions)

SDVariable max(String name, SDVariable x, int[] dimensions)

Max array reduction operation, optionally along specified dimensions

Note that if keepDims = true, the output variable has the same rank as the input variable,

the mean along a dimension).

Example: if input has shape [a,b,c] and dimensions=[1] then output has shape:

keepDims = true: [a,1,c]

keepDims = false: [a,c]

**x**(NUMERIC) - Input variable**keepDims**- If true: keep the dimensions that are reduced on (as size 1). False: remove the reduction dimensions - default = false**dimensions**- Dimensions to reduce over. If dimensions are not specified, full array reduction is performed (Size: AtLeast(min=0))

INDArray max(INDArray first, INDArray second)

SDVariable max(SDVariable first, SDVariable second)

SDVariable max(String name, SDVariable first, SDVariable second)

Element-wise maximum operation: out[i] = max(first[i], second[i])

Note: supports broadcasting if x and y have different shapes and are broadcastable.

For example, if X has shape [1,10] and Y has shape [5,10] then op(X,Y) has output shape [5,10]

**first**(NUMERIC) - First input array**second**(NUMERIC) - Second input array

INDArray mean(INDArray x, boolean keepDims, int[] dimensions)

INDArray mean(INDArray x, int[] dimensions)

SDVariable mean(SDVariable x, boolean keepDims, int[] dimensions)

SDVariable mean(SDVariable x, int[] dimensions)

SDVariable mean(String name, SDVariable x, boolean keepDims, int[] dimensions)

SDVariable mean(String name, SDVariable x, int[] dimensions)

Mean (average) array reduction operation, optionally along specified dimensions

Note that if keepDims = true, the output variable has the same rank as the input variable,

the mean along a dimension).

Example: if input has shape [a,b,c] and dimensions=[1] then output has shape:

keepDims = true: [a,1,c]

keepDims = false: [a,c]

**x**(NUMERIC) - Input variable