public interface NDArrayAdapter extends NDArray
NDArray
that does nothing. This can be used for overriding
the NDArray with only part of the interface implemented.
This interface should only be used for the NDArray implementations that do not plan to
implement a large portion of the interface. For the ones that do, they should directly implement
NDArray
so that the unsupported operations are better highlighted in the code.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
UNSUPPORTED_MSG |
Modifier and Type | Method and Description |
---|---|
default NDArray |
abs()
Returns the absolute value of this
NDArray element-wise. |
default NDArray |
acos()
Returns the inverse trigonometric cosine of this
NDArray element-wise. |
default NDArray |
acosh()
Returns the inverse hyperbolic cosine of this
NDArray element-wise. |
default NDArray |
add(NDArray other)
Adds other
NDArray s to this NDArray element-wise. |
default NDArray |
add(java.lang.Number n)
Adds a number to this
NDArray element-wise. |
default NDArray |
addi(NDArray other)
Adds other
NDArray s to this NDArray element-wise in place. |
default NDArray |
addi(java.lang.Number n)
Adds a number to this
NDArray element-wise in place. |
default NDArray |
argMax()
Returns the indices of the maximum values into the flattened
NDArray . |
default NDArray |
argMax(int axis)
Returns the indices of the maximum values along given axis.
|
default NDArray |
argMin()
Returns the indices of the minimum values into the flattened
NDArray . |
default NDArray |
argMin(int axis)
Returns the indices of the minimum values along given axis.
|
default NDArray |
argSort(int axis,
boolean ascending)
Returns the indices that would sort this
NDArray given the axis. |
default NDArray |
asin()
Returns the inverse trigonometric sine of this
NDArray element-wise. |
default NDArray |
asinh()
Returns the inverse hyperbolic sine of this
NDArray element-wise. |
default NDArray |
atan()
Returns the inverse trigonometric tangent of this
NDArray element-wise. |
default NDArray |
atanh()
Returns the inverse hyperbolic tangent of this
NDArray element-wise. |
default void |
attach(NDManager manager)
Attaches this
NDResource to the specified NDManager . |
default NDArray |
batchDot(NDArray other)
Batchwise product of this
NDArray and the other NDArray . |
default NDArray |
booleanMask(NDArray index,
int axis)
Returns portion of this
NDArray given the index boolean NDArray along given
axis. |
default NDArray |
broadcast(Shape shape)
Broadcasts this
NDArray to be the given shape. |
default NDArray |
cbrt()
Returns the cube-root of this
NDArray element-wise. |
default NDArray |
ceil()
Returns the ceiling of this
NDArray element-wise. |
default NDArray |
clip(java.lang.Number min,
java.lang.Number max)
Clips (limit) the values in this
NDArray . |
default boolean |
contentEquals(NDArray other)
|
default boolean |
contentEquals(java.lang.Number number)
Returns
true if all elements in this NDArray are equal to the Number . |
default void |
copyTo(NDArray array)
Deep-copies the current
NDArray to the one passed in. |
default NDArray |
cos()
Returns the trigonometric cosine of this
NDArray element-wise. |
default NDArray |
cosh()
Returns the hyperbolic cosine of this
NDArray element-wise. |
default NDArray |
cumSum()
Returns the cumulative sum of the elements in the flattened
NDArray . |
default NDArray |
cumSum(int axis)
Return the cumulative sum of the elements along a given axis.
|
default void |
detach()
Detaches the
NDResource from current NDManager 's lifecycle. |
default NDArray |
div(NDArray other)
Divides this
NDArray by the other NDArray element-wise. |
default NDArray |
div(java.lang.Number n)
Divides this
NDArray by a number element-wise. |
default NDArray |
divi(NDArray other)
Divides this
NDArray by the other NDArray element-wise in place. |
default NDArray |
divi(java.lang.Number n)
Divides this
NDArray by a number element-wise in place. |
default NDArray |
dot(NDArray other)
Dot product of this
NDArray and the other NDArray . |
default NDArray |
eq(NDArray other)
Returns the boolean
NDArray for element-wise "Equals" comparison. |
default NDArray |
eq(java.lang.Number n)
Returns the boolean
NDArray for element-wise "Equals" comparison. |
default NDArray |
erfinv()
Returns element-wise inverse gauss error function of the
NDArray . |
default NDArray |
exp()
Returns the exponential value of this
NDArray element-wise. |
default NDArray |
expandDims(int axis)
Expands the
Shape of a NDArray . |
default NDArray |
flatten()
Flattens this
NDArray into a 1-D NDArray in row-major order. |
default NDArray |
flip(int... axes)
Returns the reverse order of elements in an array along the given axis.
|
default NDArray |
floor()
Returns the floor of this
NDArray element-wise. |
default DataType |
getDataType()
Returns the
DataType of this NDArray . |
default Device |
getDevice()
Returns the
Device of this NDArray . |
default NDArray |
getGradient()
Returns the gradient
NDArray attached to this NDArray . |
default NDManager |
getManager()
Returns the
NDManager that manages this. |
default java.lang.String |
getName()
Returns the name of this
NDArray . |
default ai.djl.ndarray.internal.NDArrayEx |
getNDArrayInternal()
Returns an internal representative of Native
NDArray . |
default Shape |
getShape()
Returns the
Shape of this NDArray . |
default SparseFormat |
getSparseFormat()
Returns the
SparseFormat of this NDArray . |
default java.lang.String |
getUid()
Returns unique identifier of this
NDArray . |
default NDArray |
gt(NDArray other)
Returns the boolean
NDArray for element-wise "Greater Than" comparison. |
default NDArray |
gt(java.lang.Number n)
Returns the boolean
NDArray for element-wise "Greater" comparison. |
default NDArray |
gte(NDArray other)
Returns the boolean
NDArray for element-wise "Greater or equals" comparison. |
default NDArray |
gte(java.lang.Number n)
Returns the boolean
NDArray for element-wise "Greater or equals" comparison. |
default boolean |
hasGradient()
Returns true if the gradient calculation is required for this
NDArray . |
default void |
intern(NDArray replaced)
Replace the handle of the NDArray with the other.
|
default NDArray |
isInfinite()
Returns the boolean
NDArray with value true where this NDArray 's
entries are infinite, or false where they are not infinite. |
default NDArray |
isNaN()
Returns the boolean
NDArray with value true where this NDArray 's
entries are NaN, or false where they are not NaN. |
default NDArray |
log()
Returns the natural logarithmic value of this
NDArray element-wise. |
default NDArray |
log10()
Returns the base 10 logarithm of this
NDArray element-wise. |
default NDArray |
log2()
Returns the base 2 logarithm of this
NDArray element-wise. |
default NDArray |
logicalAnd(NDArray other)
Returns the truth value of this
NDArray AND the other NDArray element-wise. |
default NDArray |
logicalNot()
Computes the truth value of NOT this
NDArray element-wise. |
default NDArray |
logicalOr(NDArray other)
Computes the truth value of this
NDArray OR the other NDArray element-wise. |
default NDArray |
logicalXor(NDArray other)
Computes the truth value of this
NDArray XOR the other NDArray element-wise. |
default NDArray |
logSoftmax(int axis)
Applies the softmax function followed by a logarithm.
|
default NDArray |
lt(NDArray other)
Returns the boolean
NDArray for element-wise "Less" comparison. |
default NDArray |
lt(java.lang.Number n)
Returns the boolean
NDArray for element-wise "Less" comparison. |
default NDArray |
lte(NDArray other)
Returns the boolean
NDArray for element-wise "Less or equals" comparison. |
default NDArray |
lte(java.lang.Number n)
Returns the boolean
NDArray for element-wise "Less or equals" comparison. |
default NDArray |
matMul(NDArray other)
Product matrix of this
NDArray and the other NDArray . |
default NDArray |
max()
Returns the maximum of this
NDArray . |
default NDArray |
max(int[] axes,
boolean keepDims)
Returns the maximum of this
NDArray along given axes. |
default NDArray |
maximum(NDArray other)
Returns the maximum of this
NDArray and the other NDArray element-wise. |
default NDArray |
maximum(java.lang.Number n)
Returns the maximum of this
NDArray and a number element-wise. |
default NDArray |
mean()
Returns the average of this
NDArray . |
default NDArray |
mean(int[] axes,
boolean keepDims)
Returns the average of this
NDArray along given axes. |
default NDArray |
median()
Returns median value for this
NDArray . |
default NDArray |
median(int[] axes)
Returns median value along given axes.
|
default NDArray |
min()
Returns the minimum of this
NDArray . |
default NDArray |
min(int[] axes,
boolean keepDims)
Returns the minimum of this
NDArray along given axes. |
default NDArray |
minimum(NDArray other)
Returns the maximum of this
NDArray and the other NDArray element-wise. |
default NDArray |
minimum(java.lang.Number n)
Returns the minimum of this
NDArray and a number element-wise. |
default NDArray |
mod(NDArray other)
Returns element-wise remainder of division.
|
default NDArray |
mod(java.lang.Number n)
Returns element-wise remainder of division.
|
default NDArray |
modi(NDArray other)
Returns in place element-wise remainder of division in place.
|
default NDArray |
modi(java.lang.Number n)
Returns element-wise remainder of division in place.
|
default NDArray |
mul(NDArray other)
Multiplies this
NDArray by other NDArray s element-wise. |
default NDArray |
mul(java.lang.Number n)
Multiplies this
NDArray by a number element-wise. |
default NDArray |
muli(NDArray other)
Multiplies this
NDArray by other NDArray element-wise in place. |
default NDArray |
muli(java.lang.Number n)
Multiplies this
NDArray by a number element-wise in place. |
default NDArray |
neg()
Returns the numerical negative
NDArray element-wise. |
default NDArray |
negi()
Returns the numerical negative
NDArray element-wise in place. |
default NDArray |
neq(NDArray other)
Returns the boolean
NDArray for element-wise "Not equals" comparison. |
default NDArray |
neq(java.lang.Number n)
Returns the boolean
NDArray for element-wise "Not equals" comparison. |
default NDArray |
nonzero()
Returns the indices of elements that are non-zero.
|
default NDArray |
norm(boolean keepDims)
Returns the norm of this
NDArray . |
default NDArray |
norm(int ord,
int[] axes,
boolean keepDims)
Returns the norm of this
NDArray . |
default NDArray |
oneHot(int depth,
float onValue,
float offValue,
DataType dataType)
Returns a one-hot
NDArray . |
default NDArray |
onesLike()
|
default NDArray |
percentile(java.lang.Number percentile)
Returns percentile for this
NDArray . |
default NDArray |
percentile(java.lang.Number percentile,
int[] axes)
Returns median along given dimension(s).
|
default NDArray |
pow(NDArray other)
Takes the power of this
NDArray with the other NDArray element-wise. |
default NDArray |
pow(java.lang.Number n)
Takes the power of this
NDArray with a number element-wise. |
default NDArray |
powi(NDArray other)
Takes the power of this
NDArray with the other NDArray element-wise in place. |
default NDArray |
powi(java.lang.Number n)
Takes the power of this
NDArray with a number element-wise in place. |
default NDArray |
prod()
Returns the product of this
NDArray . |
default NDArray |
prod(int[] axes,
boolean keepDims)
Returns the product of this
NDArray elements over the given axes. |
default NDArray |
repeat(int axis,
long repeats)
Repeats element of this
NDArray the number of times given repeats along given axis. |
default NDArray |
repeat(long repeats)
Repeats element of this
NDArray the number of times given repeats. |
default NDArray |
repeat(long[] repeats)
Repeats element of this
NDArray the number of times given repeats along each axis. |
default NDArray |
repeat(Shape desiredShape)
Repeats element of this
NDArray to match the desired shape. |
default NDArray |
reshape(Shape shape)
Reshapes this
NDArray to the given Shape . |
default NDArray |
rotate90(int times,
int[] axes)
Rotates an array by 90 degrees in the plane specified by axes.
|
default NDArray |
round()
Returns the round of this
NDArray element-wise. |
default NDArray |
sequenceMask(NDArray sequenceLength)
Sets all elements outside the sequence to 0.
|
default NDArray |
sequenceMask(NDArray sequenceLength,
float value)
Sets all elements outside the sequence to a constant value.
|
default void |
set(java.nio.Buffer data)
Sets this
NDArray value from Buffer . |
default void |
setName(java.lang.String name)
Sets name of this
NDArray . |
default void |
setRequiresGradient(boolean requiresGrad)
Attaches a gradient
NDArray to this NDArray and marks it so GradientCollector.backward(NDArray) can compute the gradient with respect to
it. |
default NDArray |
sign()
Returns the element-wise sign.
|
default NDArray |
signi()
Returns the element-wise sign in-place.
|
default NDArray |
sin()
Returns the trigonometric sine of this
NDArray element-wise. |
default NDArray |
sinh()
Returns the hyperbolic sine of this
NDArray element-wise. |
default NDArray |
softmax(int axis)
Applies the softmax function along the given axis.
|
default NDArray |
sort()
Sorts the flattened
NDArray . |
default NDArray |
sort(int axis)
Sorts the flattened
NDArray . |
default NDList |
split(long[] indices,
int axis)
Splits this
NDArray into multiple sub-NDArray s given indices along given
axis. |
default NDArray |
sqrt()
Returns the square root of this
NDArray element-wise. |
default NDArray |
square()
Returns the square of this
NDArray element-wise. |
default NDArray |
squeeze(int[] axes)
Removes singleton dimensions at the given axes.
|
default NDArray |
stopGradient()
Returns an NDArray equal to this that stop gradient propagation through it.
|
default NDArray |
sub(NDArray other)
Subtracts the other
NDArray from this NDArray element-wise. |
default NDArray |
sub(java.lang.Number n)
Subtracts a number from this
NDArray element-wise. |
default NDArray |
subi(NDArray other)
Subtracts the other
NDArray from this NDArray element-wise in place. |
default NDArray |
subi(java.lang.Number n)
Subtracts a number from this
NDArray element-wise in place. |
default NDArray |
sum()
Returns the sum of this
NDArray . |
default NDArray |
sum(int[] axes,
boolean keepDims)
Returns the sum of this
NDArray along given axes. |
default NDArray |
tan()
Returns the trigonometric tangent of this
NDArray element-wise. |
default NDArray |
tanh()
Returns the hyperbolic tangent of this
NDArray element-wise. |
default NDArray |
tile(int axis,
long repeats)
Constructs a
NDArray by repeating this NDArray the number of times given by
repeats along given axis. |
default NDArray |
tile(long repeats)
Constructs a
NDArray by repeating this NDArray the number of times given
repeats. |
default NDArray |
tile(long[] repeats)
Constructs a
NDArray by repeating this NDArray the number of times given by
repeats. |
default NDArray |
tile(Shape desiredShape)
Constructs a
NDArray by repeating this NDArray the number of times to match
the desired shape. |
default java.nio.ByteBuffer |
toByteBuffer()
Converts this
NDArray to a ByteBuffer. |
default NDArray |
toDegrees()
Converts this
NDArray from radians to degrees element-wise. |
default NDArray |
toDense()
Returns a dense representation of the sparse
NDArray . |
default NDArray |
toDevice(Device device,
boolean copy)
Moves this
NDArray to a different Device . |
default NDArray |
toRadians()
Converts this
NDArray from degrees to radians element-wise. |
default NDArray |
toSparse(SparseFormat fmt)
Returns a sparse representation of
NDArray . |
default java.lang.String[] |
toStringArray()
Converts this
NDArray to a String array. |
default NDArray |
toType(DataType dataType,
boolean copy)
Converts this
NDArray to a different DataType . |
default NDArray |
trace(int offset,
int axis1,
int axis2)
Returns the sum along diagonals of this
NDArray . |
default NDArray |
transpose()
Returns this
NDArray with axes transposed. |
default NDArray |
transpose(int... axes)
Returns this
NDArray with given axes transposed. |
default NDArray |
trunc()
Returns the truncated value of this
NDArray element-wise. |
default NDArray |
zerosLike()
|
all, allClose, allClose, any, argSort, argSort, booleanMask, broadcast, close, concat, concat, countNonzero, countNonzero, decode, duplicate, encode, get, get, get, get, getBoolean, getByte, getDouble, getFloat, getInt, getLong, getScalar, getUint8, isEmpty, isScalar, isSparse, like, max, mean, min, none, norm, norm, norm, oneHot, prod, reshape, scaleGradient, set, set, set, set, set, set, set, set, set, setScalar, shapeEquals, size, size, split, split, split, squeeze, squeeze, stack, stack, sum, swapAxes, toArray, toBooleanArray, toByteArray, toDebugString, toDoubleArray, toFloatArray, toIntArray, toLongArray, toUint8Array, trace, trace
tempAttach
static final java.lang.String UNSUPPORTED_MSG
default NDManager getManager()
NDManager
that manages this.getManager
in interface NDResource
NDManager
that manages this.default java.lang.String getName()
NDArray
.default void setName(java.lang.String name)
NDArray
.default java.lang.String getUid()
NDArray
.default DataType getDataType()
DataType
of this NDArray
.
DataType
is a definition of the precision level of the NDArray
. All values
inside the same NDArray
would have the same DataType
.
getDataType
in interface NDArray
DataType
of this NDArray
default Device getDevice()
default Shape getShape()
default SparseFormat getSparseFormat()
SparseFormat
of this NDArray
.getSparseFormat
in interface NDArray
SparseFormat
of this NDArray
default void attach(NDManager manager)
NDResource
to the specified NDManager
.
Attached resource will be closed when the NDManager
is closed.
attach
in interface NDResource
manager
- the NDManager
to be attached todefault void detach()
NDResource
from current NDManager
's lifecycle.
This becomes un-managed and it is the user's responsibility to close this. Failure to close the resource might cause your machine to run out of native memory.
detach
in interface NDResource
NDManager
default NDArray toDevice(Device device, boolean copy)
NDArray
to a different Device
.default NDArray toType(DataType dataType, boolean copy)
NDArray
to a different DataType
.default void setRequiresGradient(boolean requiresGrad)
NDArray
to this NDArray
and marks it so GradientCollector.backward(NDArray)
can compute the gradient with respect to
it.setRequiresGradient
in interface NDArray
requiresGrad
- if NDArray
requires gradient or notdefault NDArray getGradient()
NDArray
attached to this NDArray
.getGradient
in interface NDArray
NDArray
default boolean hasGradient()
NDArray
.hasGradient
in interface NDArray
NDArray
else falsedefault NDArray stopGradient()
stopGradient
in interface NDArray
default java.lang.String[] toStringArray()
NDArray
to a String array.
This method is only applicable to the String typed NDArray and not for printing purpose
toStringArray
in interface NDArray
default java.nio.ByteBuffer toByteBuffer()
NDArray
to a ByteBuffer.toByteBuffer
in interface NDArray
default void set(java.nio.Buffer data)
NDArray
value from Buffer
.default void copyTo(NDArray array)
NDArray
to the one passed in.default NDArray booleanMask(NDArray index, int axis)
NDArray
given the index boolean NDArray
along given
axis.booleanMask
in interface NDArray
index
- boolean NDArray
maskaxis
- an integer that represents the axis of NDArray
to mask fromNDArray
default NDArray sequenceMask(NDArray sequenceLength, float value)
This function takes an n-dimensional input array of the form [batch_size,
max_sequence_length, ....] and returns an array of the same shape. Parameter sequenceLength
is used to handle variable-length sequences. sequence_length should be an
input array of positive ints of dimension [batch_size].
sequenceMask
in interface NDArray
sequenceLength
- used to handle variable-length sequencesvalue
- the constant value to be setNDArray
default NDArray sequenceMask(NDArray sequenceLength)
This function takes an n-dimensional input array of the form [batch_size,
max_sequence_length, ....] and returns an array of the same shape. Parameter sequenceLength
is used to handle variable-length sequences. sequence_length should be an
input array of positive ints of dimension [batch_size].
sequenceMask
in interface NDArray
sequenceLength
- used to handle variable-length sequencesNDArray
default NDArray zerosLike()
NDArray
of zeros with the same Shape
, DataType
and SparseFormat
as the input NDArray
.
Examples
jshell> NDArray array = manager.arange(6f).reshape(2, 3); jshell> array; ND: (2, 3) cpu() float32 [[0., 1., 2.], [3., 4., 5.], ] jshell> array.zerosLike(); ND: (2, 3) cpu() float32 [[0., 0., 0.], [0., 0., 0.], ]
default NDArray onesLike()
NDArray
of ones with the same Shape
, DataType
and SparseFormat
as the input NDArray
.
Examples
jshell> NDArray array = manager.arange(6f).reshape(2, 3); jshell> array; ND: (2, 3) cpu() float32 [[0., 1., 2.], [3., 4., 5.], ] jshell> array.onesLike(); ND: (2, 3) cpu() float32 [[1., 1., 1.], [1., 1., 1.], ]
default boolean contentEquals(java.lang.Number number)
true
if all elements in this NDArray
are equal to the Number
.
Examples
jshell> NDArray array = manager.ones(new Shape(2, 3)); jshell> array.contentEquals(1); // return true instead of boolean NDArray true
contentEquals
in interface NDArray
number
- the number to comparedefault boolean contentEquals(NDArray other)
true
if all elements in this NDArray
are equal to the other NDArray
.
Examples
jshell> NDArray array1 = manager.arange(6f).reshape(2, 3); jshell> NDArray array2 = manager.create(new float[] {0f, 1f, 2f, 3f, 4f, 5f}, new Shape(2, 3)); jshell> array1.contentEquals(array2); // return true instead of boolean NDArray true
contentEquals
in interface NDArray
other
- the other NDArray
to comparedefault NDArray eq(java.lang.Number n)
NDArray
for element-wise "Equals" comparison.
Examples
jshell> NDArray array = manager.ones(new Shape(1)); jshell> array.eq(1); ND: (1) cpu() boolean [ true]
default NDArray eq(NDArray other)
NDArray
for element-wise "Equals" comparison.
Examples
jshell> NDArray array1 = manager.create(new float[] {0f, 1f, 3f}); jshell> NDArray array2 = manager.arange(3f); jshell> array1.eq(array2); ND: (3) cpu() boolean [ true, true, false]
default NDArray neq(java.lang.Number n)
NDArray
for element-wise "Not equals" comparison.
Examples
jshell> NDArray array = manager.arange(4f).reshape(2, 2); jshell> array.neq(1); ND: (2, 2) cpu() boolean [[ true, false], [ true, true], ]
default NDArray neq(NDArray other)
NDArray
for element-wise "Not equals" comparison.
Examples
jshell> NDArray array1 = manager.create(new float[] {1f, 2f}); jshell> NDArray array2 = manager.create(new float[] {1f, 3f}); jshell> array1.neq(array2); ND: (2) cpu() boolean [false, true] jshell> NDArray array1 = manager.create(new float[] {1f, 2f}); jshell> NDArray array2 = manager.create(new float[] {1f, 3f, 1f, 4f}, new Shape(2, 2)); jshell> array1.neq(array2); // broadcasting ND: (2, 2) cpu() boolean [[false, true], [false, true], ]
default NDArray gt(java.lang.Number n)
NDArray
for element-wise "Greater" comparison.
Examples
jshell> NDArray array = manager.create(new float[] {4f, 2f}); jshell> array.gt(2f); ND: (2) cpu() boolean [ true, false]
default NDArray gt(NDArray other)
NDArray
for element-wise "Greater Than" comparison.
Examples
jshell> NDArray array1 = manager.create(new float[] {4f, 2f}); jshell> NDArray array2 = manager.create(new float[] {2f, 2f}); jshell> array1.neq(array2); ND: (2) cpu() boolean [ true, false]
default NDArray gte(java.lang.Number n)
NDArray
for element-wise "Greater or equals" comparison.
jshell> NDArray array = manager.create(new float[] {4f, 2f}); jshell> array.gte(2f); ND: (2) cpu() boolean [ true, true]
default NDArray gte(NDArray other)
NDArray
for element-wise "Greater or equals" comparison.
Examples
jshell> NDArray array1 = manager.create(new float[] {4f, 2f}); jshell> NDArray array2 = manager.create(new float[] {2f, 2f}); jshell> array1.gte(array2); ND: (2) cpu() boolean [ true, true]
default NDArray lt(java.lang.Number n)
NDArray
for element-wise "Less" comparison.
Examples
jshell> NDArray array = manager.create(new float[] {1f, 2f}); jshell> array.lt(2f); ND: (2) cpu() boolean [ true, false]
default NDArray lt(NDArray other)
NDArray
for element-wise "Less" comparison.
Examples
jshell> NDArray array1 = manager.create(new float[] {1f, 2f}); jshell> NDArray array2 = manager.create(new float[] {2f, 2f}); jshell> array1.lt(array2); ND: (2) cpu() boolean [ true, false]
default NDArray lte(java.lang.Number n)
NDArray
for element-wise "Less or equals" comparison.
Examples
jshell> NDArray array = manager.create(new float[] {1f, 2f}); jshell> array.lte(2f); ND: (2) cpu() boolean [ true, true]
default NDArray lte(NDArray other)
NDArray
for element-wise "Less or equals" comparison.
Examples
jshell> NDArray array1 = manager.create(new float[] {1f, 2f}); jshell> NDArray array2 = manager.create(new float[] {2f, 2f}); jshell> array1.lte(array2); ND: (2) cpu() boolean [ true, true]
default NDArray add(java.lang.Number n)
NDArray
element-wise.
Examples
jshell> NDArray array = manager.create(new float[] {1f, 2f}); jshell> array.add(2f); ND: (2) cpu() float32 [3., 4.]
default NDArray add(NDArray other)
NDArray
s to this NDArray
element-wise.
The shapes of this NDArray
and other NDArray
must be broadcastable.
Examples
jshell> NDArray array1 = manager.arange(9f).reshape(3, 3); jshell> NDArray array2 = manager.arange(3f); jshell> array1.add(array2); // broadcasting ND: (3, 3) cpu() float32 [[ 0., 2., 4.], [ 3., 5., 7.], [ 6., 8., 10.], ]
default NDArray sub(java.lang.Number n)
NDArray
element-wise.
Examples
jshell> NDArray array = manager.create(new float[] {1f, 2f}); jshell> array.sub(2f); ND: (2) cpu() float32 [-1., 0.]
default NDArray sub(NDArray other)
NDArray
from this NDArray
element-wise.
The shapes of this NDArray
and other NDArray
s must be broadcastable.
Examples
jshell> NDArray array1 = manager.arange(9).reshape(3, 3); jshell> NDArray array2 = manager.arange(3); jshell> array1.sub(array2); // broadcasting ND: (3, 3) cpu() float32 [[0., 0., 0.], [3., 3., 3.], [6., 6., 6.], ]
default NDArray mul(java.lang.Number n)
NDArray
by a number element-wise.
Examples
jshell> NDArray array = manager.create(new float[] {1f, 2f}); jshell> array.mul(3f); ND: (2) cpu() float32 [3., 6.]
default NDArray mul(NDArray other)
NDArray
by other NDArray
s element-wise.
The shapes of this NDArray
and other NDArray
must be broadcastable.
Examples
jshell> NDArray array1 = manager.arange(9f).reshape(3, 3); jshell> NDArray array2 = manager.arange(3f); jshell> array1.mul(array2); // broadcasting ND: (3, 3) cpu() float32 [[ 0., 1., 4.], [ 0., 4., 10.], [ 0., 7., 16.], ]
default NDArray div(java.lang.Number n)
NDArray
by a number element-wise.
Examples
jshell> NDArray array = manager.arange(5f); jshell> array.div(4f); ND: (5) cpu() float32 [0. , 0.25, 0.5 , 0.75, 1. ]
default NDArray div(NDArray other)
NDArray
by the other NDArray
element-wise.
The shapes of this NDArray
and the other NDArray
must be broadcastable.
Examples
jshell> NDArray array1 = manager.arange(9f).reshape(3, 3); jshell> NDArray array2 = manager.ones(new Shape(3)).mul(10); jshell> array1.div(array2); // broadcasting ND: (3, 3) cpu() float32 [[0. , 0.1, 0.2], [0.3, 0.4, 0.5], [0.6, 0.7, 0.8], ]
default NDArray mod(java.lang.Number n)
Examples
jshell> NDArray array = manager.arange(7f); jshell> array.mod(5f); ND: (7) cpu() float32 [0., 1., 2., 3., 4., 0., 1.]
default NDArray mod(NDArray other)
The shapes of this NDArray
and the other NDArray
must be broadcastable.
Examples
jshell> NDArray array1 = manager.create(new float[] {4f, 7f}); jshell> NDArray array2 = manager.create(new float[] {2f, 3f}); jshell> array1.mod(array2); ND: (2) cpu() float32 [0., 1.]
default NDArray pow(java.lang.Number n)
NDArray
with a number element-wise.
Examples
jshell> NDArray array = manager.arange(5f); jshell> array.pow(4f); ND: (6) cpu() float32 [ 0., 1., 8., 27., 64., 125.]
default NDArray pow(NDArray other)
NDArray
with the other NDArray
element-wise.
Examples
jshell> NDArray array1 = manager.arange(6f).reshape(3, 2); jshell> NDArray array2 = manager.create(new float[] {2f, 3f}); jshell> array1.pow(array2); // broadcasting ND: (3, 2) cpu() float32 [[ 0., 1.], [ 4., 27.], [ 16., 125.], ]
default NDArray addi(java.lang.Number n)
NDArray
element-wise in place.
Examples
jshell> NDArray array = manager.create(new float[] {1f, 2f}); jshell> array.addi(2f); ND: (2) cpu() float32 [3., 4.] jshell> array; ND: (2) cpu() float32 [3., 4.]
default NDArray addi(NDArray other)
NDArray
s to this NDArray
element-wise in place.
The shapes of this NDArray
and other NDArray
s must be broadcastable.
Examples
jshell> NDArray array1 = manager.create(new float[] {1f, 2f}); jshell> NDArray array2 = manager.create(new float[] {3f, 4f}); jshell> array1.addi(array2); ND: (2) cpu() float32 [4., 6.] jshell> array; ND: (2) cpu() float32 [4., 6.]
default NDArray subi(java.lang.Number n)
NDArray
element-wise in place.
Examples
jshell> NDArray array = manager.create(new float[] {1f, 2f}); jshell> array.subi(2f); ND: (2) cpu() float32 [-1., 0.] jshell> array; ND: (2) cpu() float32 [-1., 0.]
default NDArray subi(NDArray other)
NDArray
from this NDArray
element-wise in place.
The shapes of this NDArray
and other NDArray
s must be broadcastable.
Examples
jshell> NDArray array1 = manager.arange(9f).reshape(3, 3); jshell> NDArray array2 = manager.arange(3f); jshell> array1.subi(array2); // broadcasting ND: (3, 3) cpu() float32 [[0., 0., 0.], [3., 3., 3.], [6., 6., 6.], ] jshell> array1; [[0., 0., 0.], [3., 3., 3.], [6., 6., 6.], ]
default NDArray muli(java.lang.Number n)
NDArray
by a number element-wise in place.
Examples
jshell> NDArray array = manager.create(new float[] {1f, 2f}); jshell> array.muli(3f); ND: (2) cpu() float32 [3., 6.] jshell> array; ND: (2) cpu() float32 [3., 6.]
default NDArray muli(NDArray other)
NDArray
by other NDArray
element-wise in place.
The shapes of this NDArray
and other NDArray
s must be broadcastable.
Examples
jshell> NDArray array1 = manager.arange(9f).reshape(3, 3); jshell> NDArray array2 = manager.arange(3f); jshell> array1.muli(array2); // broadcasting ND: (3, 3) cpu() float32 [[ 0., 1., 4.], [ 0., 4., 10.], [ 0., 7., 16.], ] jshell> array1; ND: (3, 3) cpu() float32 [[ 0., 1., 4.], [ 0., 4., 10.], [ 0., 7., 16.], ]
default NDArray divi(java.lang.Number n)
NDArray
by a number element-wise in place.
Examples
jshell> NDArray array = manager.arange(5f); jshell> array.divi(4f); ND: (5) cpu() float32 [0. , 0.25, 0.5 , 0.75, 1. ] jshell> array; ND: (5) cpu() float32 [0. , 0.25, 0.5 , 0.75, 1. ]
default NDArray divi(NDArray other)
NDArray
by the other NDArray
element-wise in place.
The shapes of this NDArray
and the other NDArray
must be broadcastable.
Examples
jshell> NDArray array1 = manager.arange(9f).reshape(3, 3); jshell> NDArray array2 = manager.ones(new Shape(3)).mul(10); jshell> array1.divi(array2); // broadcasting ND: (3, 3) cpu() float32 [[0. , 0.1, 0.2], [0.3, 0.4, 0.5], [0.6, 0.7, 0.8], ] jshell> array1; [[0. , 0.1, 0.2], [0.3, 0.4, 0.5], [0.6, 0.7, 0.8], ]
default NDArray modi(java.lang.Number n)
Examples
jshell> NDArray array = manager.arange(7f); jshell> array.modi(5f); ND: (7) cpu() float32 [0., 1., 2., 3., 4., 0., 1.] jshell> array; ND: (7) cpu() float32 [0., 1., 2., 3., 4., 0., 1.]
default NDArray modi(NDArray other)
The shapes of this NDArray
and the other NDArray
must be broadcastable.
Examples
jshell> NDArray array1 = manager.create(new float[] {4f, 7f}); jshell> NDArray array2 = manager.create(new float[] {2f, 3f}); jshell> array1.modi(array2); ND: (2) cpu() float32 [0., 1.] jshell> array1; ND: (2) cpu() float32 [0., 1.]
default NDArray powi(java.lang.Number n)
NDArray
with a number element-wise in place.
Examples
jshell> NDArray array = manager.arange(5f); jshell> array.powi(4f); ND: (6) cpu() float32 [ 0., 1., 8., 27., 64., 125.] jshell> array; ND: (6) cpu() float32 [ 0., 1., 8., 27., 64., 125.]
default NDArray powi(NDArray other)
NDArray
with the other NDArray
element-wise in place.
The shapes of this NDArray
and the other NDArray
must be broadcastable.
Examples
jshell> NDArray array1 = manager.arange(6f).reshape(3, 2); jshell> NDArray array2 = manager.create(new float[] {2f, 3f}); jshell> array1.powi(array2); // broadcasting ND: (3, 2) cpu() float32 [[ 0., 1.], [ 4., 27.], [ 16., 125.], ] jshell> array1; ND: (3, 2) cpu() float32 [[ 0., 1.], [ 4., 27.], [ 16., 125.], ]
default NDArray sign()
default NDArray signi()
default NDArray maximum(java.lang.Number n)
NDArray
and a number element-wise.
Examples
jshell> NDArray array = manager.create(new float[] {2f, 3f, 4f}); jshell> array.maximum(3f); ND: (3) cpu() float32 [3., 3., 4.]
default NDArray maximum(NDArray other)
NDArray
and the other NDArray
element-wise.
The shapes of this NDArray
and the other NDArray
must be broadcastable.
Examples
jshell> NDArray array1 = manager.create(new float[] {2f, 3f, 4f}); jshell> NDArray array2 = manager.create(new float[] {1f, 5f, 2f}); jshell> array1.maximum(array2); ND: (3) cpu() float32 [2., 5., 4.] jshell> NDArray array1 = manager.eye(2); jshell> NDArray array2 = manager.create(new float[] {0.5f, 2f}); jshell> array1.maximum(array2); // broadcasting ND: (2, 2) cpu() float32 [[1. , 2. ], [0.5, 2. ], ]
default NDArray minimum(java.lang.Number n)
NDArray
and a number element-wise.
Examples
jshell> NDArray array = manager.create(new float[] {2f, 3f, 4f}); jshell> array.minimum(3f); ND: (3) cpu() float32 [2., 3., 3.]
default NDArray minimum(NDArray other)
NDArray
and the other NDArray
element-wise.
The shapes of this NDArray
and the other NDArray
must be broadcastable.
Examples
jshell> NDArray array1 = manager.create(new float[] {2f, 3f, 4f}); jshell> NDArray array2 = manager.create(new float[] {1f, 5f, 2f}); jshell> array1.minimum(array2); ND: (3) cpu() float32 [1., 3., 2.] jshell> NDArray array1 = manager.eye(2); jshell> NDArray array2 = manager.create(new float[] {0.5f, 2f}); jshell> array1.minimum(array2); // broadcasting ND: (2, 2) cpu() float32 [[0.5, 0. ], [0. , 1. ], ]
default NDArray neg()
NDArray
element-wise.
jshell> NDArray array = manager.arange(5f); jshell> array.neg(); ND: (5) cpu() float32 [-0., -1., -2., -3., -4.]
default NDArray negi()
NDArray
element-wise in place.
jshell> NDArray array = manager.arange(5f); jshell> array.negi(); jshell> array; ND: (5) cpu() float32 [-0., -1., -2., -3., -4.]
default NDArray abs()
NDArray
element-wise.
Examples
jshell> NDArray array = manager.create(new float[] {-1f, -2f}); jshell> array.abs(); ND: (2) cpu() float32 [1., 2.]
default NDArray square()
NDArray
element-wise.
Examples
jshell> NDArray array = manager.create(new float[] {2f, -3f}); jshell> array.square(); ND: (2) cpu() float32 [4., 9.]
default NDArray sqrt()
NDArray
element-wise.
Examples
jshell> NDArray array = manager.create(new float[] {4f}); jshell> array.sqrt(); ND: (1) cpu() float32 [2., ]
default NDArray cbrt()
NDArray
element-wise.
Examples
jshell> NDArray array = manager.create(new float[] {1f, 8f, 27f}); jshell> array.cbrt(); ND: (3) cpu() float32 [1., 2., 3.]
default NDArray floor()
NDArray
element-wise.
The floor of the scalar x is the largest integer i, such that i <= x.
Examples
jshell> NDArray array = manager.create(new float[] {-1.7f, -1.5f, -0.2f, 0.2f, 1.5f, 1.7f, 2.0f}); jshell> array.floor(); ND: (7) cpu() float32 [-2., -2., -1., 0., 1., 1., 2.]
default NDArray ceil()
NDArray
element-wise.
The ceil of the scalar x is the smallest integer i, such that i >= x.
Examples
jshell> NDArray array = manager.create(new float[] {-1.7f, -1.5f, -0.2f, 0.2f, 1.5f, 1.7f, 2.0f}); jshell> array.ceil(); ND: (7) cpu() float32 [-1., -1., -0., 1., 2., 2., 2.]
default NDArray round()
NDArray
element-wise.
Examples
jshell> NDArray array = manager.create(new float[] {-1.7f, -1.5f, -0.2f, 0.2f, 1.5f, 1.7f, 2.0f}); jshell> array.round(); ND: (7) cpu() float32 [-2., -2., -0., 0., 2., 2., 2.]
default NDArray trunc()
NDArray
element-wise.
Examples
jshell> NDArray array = manager.create(new float[] {-1.7f, -1.5f, -0.2f, 0.2f, 1.5f, 1.7f, 2.0f}); jshell> array.trunc(); ND: (7) cpu() float32 [-1., -1., -0., 0., 1., 1., 2.]
default NDArray exp()
NDArray
element-wise.
Examples
jshell> NDArray array = manager.create(new float[] {0f, 2.5f}); jshell> array.exp(); ND: (2) cpu() float32 [ 1. , 12.1825]
default NDArray log()
NDArray
element-wise.
Examples
jshell> NDArray array = manager.create(new float[] {0f, 2.5f}); jshell> array.log(); ND: (2) cpu() float32 [ -inf, 0.9163]
default NDArray log10()
NDArray
element-wise.
Examples
jshell> NDArray array = manager.create(new float[] {1000f, 1f, 150f}); jshell> array.log10(); ND: (3) cpu() float32 [3. , 0. , 2.1761]
default NDArray log2()
NDArray
element-wise.
Examples
jshell> NDArray array = manager.create(new float[] {8, 1f, 5f}); jshell> array.log2(); ND: (3) cpu() float32 [3. , 0. , 2.3219]
default NDArray sin()
NDArray
element-wise.
The input should be in radians (2 Pi radians equals 360 degrees).
Examples
jshell> NDArray array = manager.create(new float[] {0f, 30f, 45f, 60f, 90f}); jshell> array = array.mul(Math.PI).div(180f); jshell> array.sin(); ND: (5) cpu() float32 [0. , 0.5 , 0.7071, 0.866 , 1. ]
default NDArray cos()
NDArray
element-wise.
The input should be in radians (2 Pi radians equals 360 degrees).
Examples
jshell> NDArray array = manager.create(new double[] {0, Math.PI/2, Math.PI}); jshell> array.cos(); ND: (3) cpu() float64 [ 1.0000000e+00, 6.1232340e-17, -1.0000000e+00],
default NDArray tan()
NDArray
element-wise.
The input should be in radians (2 Pi radians equals 360 degrees).
Examples
jshell> NDArray array = manager.create(new double[] {-Math.PI, Math.PI/2, Math.PI}); jshell> array.tan(); ND: (3) cpu() float64 [ 1.2246468e-16, 1.6331239e+16, -1.2246468e-16],
default NDArray asin()
NDArray
element-wise.
The input should be in the range [-1, 1]. The output is in the closed interval of [-Pi/2, Pi/2].
Examples
jshell> NDArray array = manager.create(new float[] {1f, -1f, 0f}); jshell> array.asin(); ND: (3) cpu() float64 [ 1.5708, -1.5708, 0. ]
default NDArray acos()
NDArray
element-wise.
The input should be in the range [-1, 1]. The output is in the closed interval of [-Pi/2, Pi/2].
Examples
jshell> NDArray array = manager.create(new float[] {1f, -1f}); jshell> array.acos(); ND: (2) cpu() float64 [0. , 3.1416]
default NDArray atan()
NDArray
element-wise.
The input should be in the range [-1, 1]. The output is in the closed interval of [-Pi/2, Pi/2].
Examples
jshell> NDArray array = manager.create(new float[] {0f, 1f}); jshell> array.atan(); ND: (2) cpu() float64 [0. , 0.7854]
default NDArray sinh()
NDArray
element-wise.
sinh(x)=0.5*(exp(x) - exp(-x))
Examples
jshell> NDArray array = manager.create(new double[] {0, Math.PI}); jshell> array.sinh(); ND: (2) cpu() float64 [ 0. , 11.5487]
default NDArray cosh()
NDArray
element-wise.
cosh(x)=0.5*(exp(x)+exp(-x))
Examples
jshell> NDArray array = manager.create(new double[] {0, Math.PI}); jshell> array.cosh(); ND: (2) cpu() float64 [ 1. , 11.592 ]
default NDArray tanh()
NDArray
element-wise.
tanh(x)=sinh(x)/cosh(x)
Examples
jshell> NDArray array = manager.create(new double[] {0, Math.PI}); jshell> array.tanh(); ND: (2) cpu() float64 [0. , 0.9963]
default NDArray asinh()
NDArray
element-wise.
Examples
jshell> NDArray array = manager.create(new double[] {Math.E, 10}); jshell> array.asinh(); ND: (2) cpu() float64 [1.7254, 2.9982]
default NDArray acosh()
NDArray
element-wise.
Examples
jshell> NDArray array = manager.create(new double[] {Math.E, 10}); jshell> array.acosh(); ND: (2) cpu() float64 [1.6575, 2.9932]
default NDArray atanh()
NDArray
element-wise.
Examples
jshell> NDArray array = manager.create(new double[] {0, -0.5}); jshell> array.atanh(); ND: (2) cpu() float64 [ 0. , -0.5493]
default NDArray toDegrees()
NDArray
from radians to degrees element-wise.
Examples
jshell> NDArray array = manager.arange(6f).mul(Math.PI / 3); jshell> array.toDegrees(); ND: (6) cpu() float32 [ 0., 60., 120., 180., 240., 300.]
default NDArray toRadians()
NDArray
from degrees to radians element-wise.
Examples
jshell> NDArray array = manager.arange(6f).mul(60); jshell> array.toRadians(); ND: (6) cpu() float32 [0. , 1.0472, 2.0944, 3.1416, 4.1888, 5.236 ]
default NDArray max()
NDArray
.
Examples
jshell> NDArray array = manager.arange(4f).reshape(2,2); jshell> array; ND: (2, 2) cpu() float32 [[0., 1.], [2., 3.], ] jshell> array.max(); // Maximum of the flattened array ND: () cpu() float32 3. jshell> array.max().getFloat() // Use getFloat() to get native float 3.0
default NDArray max(int[] axes, boolean keepDims)
NDArray
along given axes.
Examples
jshell> NDArray array = manager.arange(4f).reshape(2,2); jshell> array; ND: (2, 2) cpu() float32 [[0., 1.], [2., 3.], ] jshell> array.max(new int[]{0}, true); // Maximum along the first axis and keep dimension ND: (1, 2) cpu() float32 [[2., 3.], ] jshell> array.max(new int[]{1}, true); // Maximum along the second axis and keep dimension ND: (2, 1) cpu() float32 [[1.], [3.], ]
default NDArray min()
NDArray
.
Examples
jshell> NDArray array = manager.arange(4f).reshape(2,2); jshell> array; ND: (2, 2) cpu() float32 [[0., 1.], [2., 3.], ] jshell> array.min(); // Minimum of the flattened array ND: () cpu() float32 0. jshell> array.min().getFloat(); // Use getFloat() to get native float 0.0
default NDArray min(int[] axes, boolean keepDims)
NDArray
along given axes.
Examples
jshell> NDArray array = manager.arange(4f).reshape(2,2); jshell> array ND: (2, 2) cpu() float32 [[0., 1.], [2., 3.], ] jshell> array.min(new int[]{0}, true) // Minimum along the first axis and keep dimension ND: (1, 2) cpu() float32 [[0., 1.], ] jshell> array.min(new int[]{1}, true) // Minimum along the second axis and keep dimension ND: (2, 1) cpu() float32 [[0.], [2.], ]
default NDArray sum()
NDArray
.
Examples
jshell> NDArray array = manager.create(new float[] {0.5f, 1.5f}); jshell> array.sum(); ND: () cpu() float32 2. jshell> array.sum().getFloat(); // Use getFloat() to get native float 2.0 jshell> NDArray array = manager.create(new float[] {0f, 1f, 0f, 5f}, new Shape(2, 2)); jshell> array.sum(); ND: () cpu() float32 6.
default NDArray sum(int[] axes, boolean keepDims)
NDArray
along given axes.
Examples
jshell> NDArray array = manager.create(new float[] {0f, 1f, 0f, 5f}, new Shape(2, 2)); jshell> array; ND: (2, 2) cpu() float32 [[0., 1.], [0., 5.], ] jshell> array.sum(new int[] {0}, true); ND: (1, 2) cpu() float32 [[0., 6.], ] jshell> array.sum(new int[] {1}, true); ND: (2, 2) cpu() float32 [[0., 1.], [0., 5.], ]
default NDArray prod()
NDArray
.
Examples
jshell> NDArray array = manager.create(new float[] {2f, 3f}); jshell> array.prod(); ND: () cpu() float32 6. jshell> array.prod().getFloat(); // Use getFloat to get native float 6.0 jshell> NDArray array = manager.create(new float[] {1f, 2f, 3f, 4f}, new Shape(2, 2)); jshell> array.prod(); ND: () cpu() float32 24.
default NDArray prod(int[] axes, boolean keepDims)
NDArray
elements over the given axes.
Examples
jshell> NDArray array = manager.create(new float[] {1f, 2f, 3f, 4f}, new Shape(2, 2)); jshell> array; ND: (2, 2) cpu() float32 [[1., 2.], [3., 4.], ] jshell> array.prod(new int[] {0}, true); ND: (1, 2) cpu() float32 [[3., 8.], ] jshell> array.prod(new int[] {1}, true); ND: (2, 1) cpu() float32 [[ 2.], [12.], ]
default NDArray mean()
NDArray
.
Examples
jshell> NDArray array = manager.create(new float[] {2f, 3f}); jshell> array.mean(); ND: () cpu() float32 2.5 jshell> array.mean().getFloat(); // Use getFloat() to get native float 2.5 jshell> NDArray array = manager.create(new float[] {1f, 2f, 3f, 4f}, new Shape(2, 2)); jshell> array.mean(); ND: () cpu() float32 2.5
default NDArray mean(int[] axes, boolean keepDims)
NDArray
along given axes.
Examples
jshell> NDArray array = manager.create(new float[] {1f, 2f, 3f, 4f}, new Shape(2, 2)); jshell> array; ND: (2, 2) cpu() float32 [[1., 2.], [3., 4.], ] jshell> array.mean(new int[] {0}, true); ND: (1, 2) cpu() float32 [[2., 3.], ] jshell> array.mean(new int[] {1}, true); ND: (2, 1) cpu() float32 [[1.5], [3.5], ]
default NDArray rotate90(int times, int[] axes)
Rotation direction is from the first towards the second axis.
default NDArray trace(int offset, int axis1, int axis2)
NDArray
.
If this NDArray
is 2-D, the sum along its diagonal with the given offset is
returned, i.e., the sum of elements a[i,i+offset] for all i. If this NDArray
has more
than two dimensions, then the axes specified by axis1 and axis2 are used to determine the 2-D
sub-arrays whose traces are returned. The Shape
of the resulting array is the same as
this NDArray
with axis1 and axis2 removed.
Examples
jshell> NDArray array = manager.arange(8f).reshape(2, 2, 2); jshell> array; ND: (2, 2, 2) cpu() float32 [[[0., 1.], [2., 3.], ], [[4., 5.], [6., 7.], ], ] jshell> array.trace(1,1,2); ND: (2) cpu() float32 [1., 5.]
trace
in interface NDArray
offset
- offset of the diagonal from the main diagonal. Can be both positive and
negative.axis1
- axes to be used as the first axis of the 2-D sub-arrays from which the diagonals
should be takenaxis2
- axes to be used as the second axis of the 2-D sub-arrays from which the
diagonals should be takenNDArray
default NDList split(long[] indices, int axis)
NDArray
into multiple sub-NDArray
s given indices along given
axis.
Examples
jshell> NDArray array = manager.arange(18f).reshape(2, 9); jshell> array; ND: (2, 9) cpu() float32 [[ 0., 1., 2., 3., 4., 5., 6., 7., 8.], [ 9., 10., 11., 12., 13., 14., 15., 16., 17.], ] jshell> array.split(new int[] {2,4,5}, 1).forEach(System.out::println); ND: (2, 2) cpu() float32 [[ 0., 1.], [ 9., 10.], ] ND: (2, 2) cpu() float32 [[ 2., 3.], [11., 12.], ] ND: (2, 1) cpu() float32 [[ 4.], [13.], ] ND: (2, 4) cpu() float32 [[ 5., 6., 7., 8.], [14., 15., 16., 17.], ]
split
in interface NDArray
indices
- the entries indicate where along axis this NDArray
is split. If an
index exceeds the dimension of this NDArray
along axis, an empty sub-array is
returned correspondinglyaxis
- the axis to split alongNDList
with numOutputs NDArray
s with Shape
(this.shape.axis /= axis)
default NDArray flatten()
NDArray
into a 1-D NDArray
in row-major order.
To flatten in column-major order, first transpose this NDArray
Examples
jshell> NDArray array = manager.create(new float[]{1f, 2f, 3f, 4f}, new Shape(2, 2)); jshell> array.flatten(); ND: (4) cpu() float32 [1., 2., 3., 4.]
default NDArray reshape(Shape shape)
NDArray
to the given Shape
.
You can reshape it to match another NDArray by calling a.reshape(b.getShape())
Examples
jshell> NDArray array = manager.arange(6f); jshell> array; ND: (6) cpu() float32 [0., 1., 2., 3., 4., 5.] jshell> array.reshape(new Shape(2, 3)); ND: (2, 3) cpu() float32 [[0., 1., 2.], [3., 4., 5.], ]
default NDArray expandDims(int axis)
Shape
of a NDArray
.
Inserts a new axis that will appear at the axis position in the expanded NDArray
shape.
Examples
jshell> NDArray array = manager.create(new float[] {1f, 2f}); jshell> array; ND: (2) cpu() float32 [1., 2.] jshell> array.expandDims(0); ND: (1, 2) cpu() float32 [[1., 2.], ] jshell> array.expandDims(1); ND: (2, 1) cpu() float32 [[1.], [2.], ]
expandDims
in interface NDArray
axis
- the position in the expanded axes where the new axis is placedNDArray
. The number of dimensions is one greater than that of the
NDArray
default NDArray squeeze(int[] axes)
Examples
jshell> NDArray array = manager.create(new float[] {0f, 1f, 2f}, new Shape(1, 3, 1)); jshell> array; ND: (1, 3, 1) cpu() float32 [[[0.], [1.], [2.], ], ] jshell> array.squeeze(new int[] {0, 2}); ND: (3) cpu() float32 [0., 1., 2.]
default NDArray logicalAnd(NDArray other)
NDArray
AND the other NDArray
element-wise.
The shapes of this NDArray
and the other NDArray
must be broadcastable.
Examples
jshell> NDArray array1 = manager.create(new boolean[] {true}); jshell> NDArray array2 = manager.create(new boolean[] {false}); jshell> array1.logicalAnd(array2); ND: (1) cpu() boolean [false] jshell> array1 = manager.create(new boolean[] {true, false}); jshell> array2 = manager.create(new boolean[] {false, false}); jshell> array1.logicalAnd(array2); ND: (2) cpu() boolean [false, false]
jshell> NDArray array = manager.arange(5f); jshell> array.gt(1).logicalAnd(array.lt(4)); ND: (5) cpu() boolean [false, false, true, true, false]
logicalAnd
in interface NDArray
other
- the other NDArray
to operate onNDArray
of the logical AND operation applied to the elements of
this NDArray
and the other NDArray
default NDArray logicalOr(NDArray other)
NDArray
OR the other NDArray
element-wise.
The shapes of this NDArray
and the other NDArray
must be broadcastable.
Examples
jshell> NDArray array1 = manager.create(new boolean[] {true}); jshell> NDArray array2 = manager.create(new boolean[] {false}); jshell> array1.logicalOr(array2); ND: (1) cpu() boolean [ true] jshell> array1 = manager.create(new boolean[] {true, false}); jshell> array2 = manager.create(new boolean[] {false, false}); jshell> array1.logicalOr(array2); ND: (2) cpu() boolean [ true, false]
jshell> NDArray array = manager.arange(5f); jshell> array.lt(1).logicalOr(array.gt(3)); ND: (5) cpu() boolean [ true, false, false, false, true]
default NDArray logicalXor(NDArray other)
NDArray
XOR the other NDArray
element-wise.
The shapes of this NDArray
and the other NDArray
must be broadcastable.
Examples
jshell> NDArray array = manager.create(new boolean[] {true}); jshell> array1.logicalXor(array2); ND: (1) cpu() boolean [ true] jshell> array1 = manager.create(new boolean[] {true, false}); jshell> array2 = manager.create(new boolean[] {false, false}); jshell> array1.logicalXor(array2); ND: (2) cpu() boolean [ true, false]
jshell> NDArray array = manager.arange(5f); jshell> array.lt(1).logicalXor(array.gt(3)); ND: (5) cpu() boolean [ true, false, false, false, true]
logicalXor
in interface NDArray
other
- the other NDArray
to operate onNDArray
of the logical XOR operation applied to the elements of
this NDArray
and the other NDArray
default NDArray logicalNot()
NDArray
element-wise.
Examples
jshell> NDArray array = manager.create(new boolean[] {true}); jshell> array.logicalNot(); ND: (1) cpu() boolean [ false]
jshell> NDArray array = manager.arange(5f); jshell> array.lt(1).logicalNot(); ND: (5) cpu() boolean [false, true, true, true, true]
logicalNot
in interface NDArray
NDArray
default NDArray argSort(int axis, boolean ascending)
NDArray
given the axis.
Perform an indirect sort along the given axis. It returns a NDArray
of indices of
the same Shape
as this NDArray
.
Examples
jshell> NDArray array = manager.create(new float[] {0f, 3f, 2f, 2f}, new Shape(2, 2)); jshell> array.argSort(0, false); ND: (2, 2) cpu() int64 [[ 1, 0], [ 0, 1], ]
argSort
in interface NDArray
axis
- the axis to sort alongascending
- whether to sort ascendingNDArray
of indices corresponding to elements in this NDArray
on the
axis, the output DataType is always DataType.INT64
default NDArray sort()
NDArray
.
Examples
jshell> NDArray array = manager.create(new float[] {1f, 4f, 3f, 1f}, new Shape(2, 2)); jshell> array; ND: (2, 2) cpu() float32 [[1., 4.], [3., 1.], ] jshell> array.sort(); // sort the flattened array ND: (2, 2) cpu() float32 [[1., 4.], [1., 3.], ]
default NDArray sort(int axis)
NDArray
.
Examples
jshell> NDArray array = manager.create(new float[] {1f, 4f, 3f, 1f}, new Shape(2, 2)); jshell> array; ND: (2, 2) cpu() float32 [[1., 4.], [3., 1.], ] jshell> array.sort(0); // sort along the first axis ND: (2, 2) cpu() float32 [[1., 4.], [1., 3.], ]
default NDArray softmax(int axis)
softmax
in interface NDArray
axis
- the axis along which to applyNDArray
NDArray.softmax(int)
default NDArray logSoftmax(int axis)
Mathematically equivalent to calling softmax and then log. This single operator is faster than calling two operators and numerically more stable when computing gradients.
logSoftmax
in interface NDArray
axis
- the axis along which to applyNDArray
default NDArray cumSum()
NDArray
.
Examples
jshell> NDArray array = manager.create(new float[] {1f, 2f, 3f, 4f, 5f, 6f}, new Shape(2, 3)); jshell> array; ND: (2, 3) cpu() float32 [[1., 2., 3.], [4., 5., 6.], ] jshell> array.cumSum(); // cumSum on flattened array ND: (6) cpu() float32 [ 1., 3., 6., 10., 15., 21.]
default NDArray cumSum(int axis)
Examples
jshell> NDArray array = manager.create(new float[] {1f, 2f, 3f, 4f, 5f, 6f}, new Shape(2, 3)); jshell> array; ND: (2, 3) cpu() float32 [[1., 2., 3.], [4., 5., 6.], ] jshell> array.cumSum(0); ND: (2, 3) cpu() float32 [[1., 2., 3.], [5., 7., 9.], ] jshell> array.cumSum(1); ND: (2, 3) cpu() float32 [[ 1., 3., 6.], [ 4., 9., 15.], ]
default void intern(NDArray replaced)
Please use with caution, this method will make the input argument unusable.
default NDArray isInfinite()
NDArray
with value true
where this NDArray
's
entries are infinite, or false
where they are not infinite.isInfinite
in interface NDArray
NDArray
with value true
if this NDArray
's entries
are infinitedefault NDArray isNaN()
NDArray
with value true
where this NDArray
's
entries are NaN, or false
where they are not NaN.
Examples
jshell> NDArray array = manager.create(new float[] {Float.POSITIVE_INFINITY, 0, Float.NaN}); jshell> array.isNaN(); ND: (3) cpu() boolean [false, false, true]
default NDArray tile(long repeats)
NDArray
by repeating this NDArray
the number of times given
repeats.
Examples
jshell> NDArray array = manager.create(new float[] {0f, 1f, 2f}); jshell> array.tile(2); ND: (6) cpu() float32 [0., 1., 2., 0., 1., 2.]
default NDArray tile(int axis, long repeats)
NDArray
by repeating this NDArray
the number of times given by
repeats along given axis.
Examples
jshell> NDArray array = manager.create(new float[] {0f, 1f, 2f}); jshell> array.tile(1, 2); ND: (1, 6) cpu() float32 [[0., 1., 2., 0., 1., 2.], ]
default NDArray tile(long[] repeats)
NDArray
by repeating this NDArray
the number of times given by
repeats.
Examples
jshell> NDArray array = manager.create(new float[] {0f, 1f, 2f}); jshell> array.tile(new long[] {2, 2}); ND: (2, 6) cpu() float32 [[0., 1., 2., 0., 1., 2.], [0., 1., 2., 0., 1., 2.], ]
default NDArray tile(Shape desiredShape)
NDArray
by repeating this NDArray
the number of times to match
the desired shape.
If the desired Shape
has fewer dimensions than this NDArray
, it will tile
against the last axis.
Examples
jshell> NDArray array = manager.create(new float[] {0f, 1f, 2f}); jshell> array.tile(new Shape(6)); ND: (6) cpu() float32 [0., 1., 2., 0., 1., 2.]
default NDArray repeat(long repeats)
NDArray
the number of times given repeats.
Examples
jshell> NDArray array = manager.create(new float[] {0f, 1f, 2f}); jshell> array.repeat(2); ND: (6) cpu() float32 [0., 0., 1., 1., 2., 2.]
default NDArray repeat(int axis, long repeats)
NDArray
the number of times given repeats along given axis.
Examples
jshell> NDArray array = manager.create(new float[] {0f, 1f, 2f, 3f}, new Shape(2, 2)); jshell> array.repeat(1, 2); ND: (6) cpu() float32 [0., 0., 1., 1., 2., 2.]
default NDArray repeat(long[] repeats)
NDArray
the number of times given repeats along each axis.
Examples
jshell> NDArray array = manager.create(new float[] {0f, 1f, 2f, 3f}, new Shape(2, 2)); jshell> array.repeat(new long[] {2, 2}); ND: (12) cpu() float32 [0., 0., 0., 0., 1., 1., 1., 1., 2., 2., 2., 2.]
default NDArray repeat(Shape desiredShape)
NDArray
to match the desired shape.
If the desired Shape
has fewer dimensions that the array, it will repeat against
the last axis.
Examples
jshell> NDArray array = manager.create(new float[] {0f, 1f, 2f, 3f}, new Shape(2, 2)); jshell> array.repeat(new Shape(4, 4)); ND: (4, 4) cpu() float32 [[0., 0., 1., 1.], [0., 0., 1., 1.], [2., 2., 3., 3.], [2., 2., 3., 3.], ]
default NDArray dot(NDArray other)
NDArray
and the other NDArray
.
NDArray
and the other NDArray
are 1-D NDArray
s, it
is inner product of vectors (without complex conjugation).
NDArray
and the other NDArray
are 2-D NDArray
s, it
is matrix multiplication.
NDArray
or the other NDArray
is 0-D NDArray
(scalar), it is equivalent to mul.
NDArray
is N-D NDArray
and the other NDArray
is 1-D
NDArray
, it is a sum product over the last axis of those.
NDArray
is N-D NDArray
and the other NDArray
is M-D
NDArray
(where M>=2), it is a sum product over the last axis of this
NDArray
and the second-to-last axis of the other NDArray
Examples
jshell> NDArray array1 = manager.create(new float[] {1f, 2f, 3f}); jshell> NDArray array2 = manager.create(new float[] {4f, 5f, 6f}); jshell> array1.dot(array2); // inner product ND: () cpu() float32 32. jshell> array1 = manager.create(new float[] {1f, 2f, 3f, 4f}, new Shape(2, 2)); jshell> array2 = manager.create(new float[] {5f, 6f, 7f, 8f}, new Shape(2, 2)); jshell> array1.dot(array2); // matrix multiplication ND: (2, 2) cpu() float32 [[19., 22.], [43., 50.], ] jshell> array1 = manager.create(new float[] {1f, 2f, 3f, 4f}, new Shape(2, 2)); jshell> array2 = manager.create(5f); jshell> array1.dot(array2); ND: (2, 2) cpu() float32 [[ 5., 10.], [15., 20.], ] jshell> array1 = manager.create(new float[] {1f, 2f, 3f, 4f}, new Shape(2, 2)); jshell> array2 = manager.create(new float[] {1f, 2f}); jshell> array1.dot(array2); ND: (2) cpu() float32 [ 5., 11.] jshell> array1 = manager.create(new float[] {1f, 2f, 3f, 4f, 5f, 6f, 7f, 8f}, new Shape(2, 2, 2)); jshell> array2 = manager.create(new float[] {1f, 2f, 3f ,4f}, new Shape(2, 2)); jshell> array1.dot(array2); ND: (2, 2, 2) cpu() float32 [[[ 7., 10.], [15., 22.], ], [[23., 34.], [31., 46.], ], ]
default NDArray matMul(NDArray other)
NDArray
and the other NDArray
.
The behavior depends on the arguments in the following way.
NDArray
and the other NDArray
are 2-D NDArray
s,
they are multiplied like conventional matrices
NDArray
or the other NDArray
is N-D NDArray
, N
> 2 , it is treated as a stack of matrices residing in the last two indexes and
broadcast accordingly.
NDArray
is 1-D NDArray
, it is promoted to a matrix by
prepending a 1 to its dimensions. After matrix multiplication the prepended 1 is
removed.
NDArray
is 1-D NDArray
, it is promoted to a matrix by
appending a 1 to its dimensions. After matrix multiplication the appended 1 is removed.
Examples
jshell> NDArray array1 = manager.create(new float[] {1f, 0f, 0f, 1f}, new Shape(2, 2)); jshell> NDArray array2 = manager.create(new float[] {4f, 1f, 2f, 2f}, new Shape(2, 2)); jshell> array1.matMul(array2); // for 2-D arrays, it is the matrix product ND: (2, 2) cpu() float32 [[4., 1.], [2., 2.], ] jshell> array1 = manager.create(new float[] {1f, 0f, 0f, 1f}, new Shape(2, 2)); jshell> array2 = manager.create(new float[] {1f, 2f}); jshell> array1.matMul(array2); ND: (2) cpu() float32 [1., 2.] jshell> array1 = manager.create(new float[] {1f, 0f, 0f, 1f}, new Shape(2, 2)); jshell> array2 = manager.create(new float[] {1f, 2f}); jshell> array1.matMul(array2); ND: (2) cpu() float32 [1., 2.] jshell> array1 = manager.arange(2f * 2f * 4f).reshape(2, 2, 4); jshell> array2 = manager.arange(2f * 2f * 4f).reshape(2, 4, 2); jshell> array1.matMul(array2).get("0, 1, 1"); ND: () cpu() float32 98.
default NDArray clip(java.lang.Number min, java.lang.Number max)
NDArray
.
Given an interval, values outside the interval are clipped to the interval edges. For example, if an interval of [0, 1] is specified, values smaller than 0 become 0, and values larger than 1 become 1.
Examples
jshell> NDArray array = manager.arange(10f); jshell> array.clip(1, 8); ND: (10) cpu() float32 [1., 1., 2., 3., 4., 5., 6., 7., 8., 8.]
default NDArray flip(int... axes)
The shape of the array is preserved, but the elements are reordered.
default NDArray transpose()
NDArray
with axes transposed.
Examples
jshell> NDArray array = manager.create(new float[] {1f, 2f ,3f, 4f}, new Shape(2, 2)); jshell> array; ND: (2, 2) cpu() float32 [[1., 2.], [3., 4.], ] jshell> array.transpose(); ND: (2, 2) cpu() float32 [[1., 3.], [2., 4.], ]
default NDArray transpose(int... axes)
NDArray
with given axes transposed.
Examples
jshell> NDArray array = manager.create(new float[] {1f, 2f ,3f, 4f}, new Shape(2, 2)); jshell> array; ND: (2, 2) cpu() float32 [[1., 2.], [3., 4.], ] jshell> array.transpose(1, 0); ND: (2, 2) cpu() float32 [[1., 3.], [2., 4.], ] jshell> array = manager.arange(8f).reshape(2, 2, 2); jshell> array; ND: (2, 2, 2) cpu() float32 [[[0., 1.], [2., 3.], ], [[4., 5.], [6., 7.], ], ] jshell> array.transpose(1, 0, 2); ND: (2, 2, 2) cpu() float32 [[[0., 1.], [4., 5.], ], [[2., 3.], [6., 7.], ], ]
default NDArray broadcast(Shape shape)
NDArray
to be the given shape.
Examples
jshell> NDArray array = manager.create(new float[] {1f, 2f ,3f, 4f}, new Shape(2, 2)); jshell> array; ND: (2, 2) cpu() float32 [[1., 2.], [3., 4.], ] jshell> array.broadcast(new Shape(2, 2, 2)); ND: (2, 2, 2) cpu() float32 [[[1., 2.], [3., 4.], ], [[1., 2.], [3., 4.], ], ]
default NDArray argMax()
NDArray
.
Examples
jshell> NDArray array = manager.arange(6f).reshape(2, 3); jshell> array; ND: (2, 3) cpu() float32 [[0., 1., 2.], [3., 4., 5.], ] jshell> array.argMax(); ND: () cpu() int64 5.
default NDArray argMax(int axis)
Examples
jshell> NDArray array = manager.arange(6f).reshape(2, 3); jshell> array; ND: (2, 3) cpu() float32 [[0., 1., 2.], [3., 4., 5.], ] jshell> array.argMax(0); ND: (3) cpu() int64 [1, 1, 1] jshell> array.argMax(1); ND: (2) cpu() int64 [2, 2]
default NDArray argMin()
NDArray
.
Examples
jshell> NDArray array = manager.arange(6f).reshape(2, 3); jshell> array; ND: (2, 3) cpu() float32 [[0., 1., 2.], [3., 4., 5.], ] jshell> array.argMin(); ND: () cpu() int64 0.
default NDArray argMin(int axis)
Examples
jshell> NDArray array = manager.arange(6f).reshape(2, 3); jshell> array; ND: (2, 3) cpu() float32 [[0., 1., 2.], [3., 4., 5.], ] jshell> array.argMin(0); ND: (3) cpu() int64 [0, 0, 0] jshell> array.argMin(1); ND: (2) cpu() int64 [0, 0]
default NDArray percentile(java.lang.Number percentile)
NDArray
.percentile
in interface NDArray
percentile
- the target percentile in range of 0..100NDArray
default NDArray percentile(java.lang.Number percentile, int[] axes)
percentile
in interface NDArray
percentile
- the target percentile in range of 0..100axes
- the dimension to calculate percentile forNDArray
NDArraydefault NDArray median()
NDArray
.default NDArray median(int[] axes)
default NDArray toDense()
NDArray
.default NDArray toSparse(SparseFormat fmt)
NDArray
.toSparse
in interface NDArray
fmt
- the SparseFormat
of this NDArray
NDArray
default NDArray nonzero()
Note that the behavior is slightly different from numpy.nonzero. Numpy returns a tuple of
NDArray, one for each dimension of NDArray. DJL nonzero returns only one NDArray
with
last dimension containing all dimension of indices.
Examples
jshell> NDArray array = manager.create(new float[] {1f, 1f, 1f, 0f, 1f}); jshell> array.nonzero(); ND: (4, 1) cpu() int64 [[ 0], [ 1], [ 2], [ 4], ] jshell> array = manager.create(new float[] {3f, 0f, 0f, 0f, 4f, 0f, 5f, 6f, 0f}).reshape(3, 3); jshell> array; ND: (3, 3) cpu() float32 [[3., 0., 0.], [0., 4., 0.], [5., 6., 0.], ] jshell> array.nonzero(); ND: (4, 2) cpu() int64 [[ 0, 0], [ 1, 1], [ 2, 0], [ 2, 1], ]
default NDArray erfinv()
NDArray
.
Examples
jshell> NDArray array = manager.create(new float[] {0f, 0.5f, -1f}); jshell> array.erfinv(); ND: (3) cpu() float32 [0., 0.4769, -inf]
default NDArray norm(boolean keepDims)
NDArray
.
Examples
jshell> NDArray array = manager.create(new float[] {-3f, -4f}); jshell> array.norm(true); ND: () cpu() float32 5. jshell> NDArray array = manager.create(new float[] {1f, 2f, 3f, 4f}, new Shape(2, 2)); jshell> array.norm(true); ND: () cpu() float32 [[5.4772], ]
default NDArray norm(int ord, int[] axes, boolean keepDims)
NDArray
.
Examples
jshell> NDArray array = manager.create(new float[] {1f, 2f, 3f, 4f}, new Shape(2, 2)); jshell> array.norm(2, new int[] {0}, true); ND: (1, 2) cpu() float32 [[3.1623, 4.4721], ] jshell> NDArray array = manager.create(new float[] {1f, 2f, 3f, 4f}, new Shape(2, 2)); jshell> array.norm(2, new int[] {0}, false); ND: (2) cpu() float32 [3.1623, 4.4721]
norm
in interface NDArray
ord
- Order of the norm.axes
- If axes contains an integer, it specifies the axis of x along which to compute
the vector norms. If axis contains 2 integers, it specifies the axes that hold 2-D
matrices, and the matrix norms of these matrices are computed.keepDims
- keepDims If this is set to True, the axes which are normed over are left in
the result as dimensions with size one. With this option the result will broadcast
correctly against the original x.NDArray
default NDArray oneHot(int depth, float onValue, float offValue, DataType dataType)
NDArray
.
NDArray
is rank N, the output will have rank N+1. The new axis is
appended at the end.
NDArray
is a scalar the output shape will be a vector of length depth.
NDArray
is a vector of length features, the output shape will be features x
depth.
NDArray
is a matrix with shape [batch, features], the output shape will be
batch x features x depth.
Examples
jshell> NDArray array = manager.create(new int[] {1, 0, 2, 0}); jshell> array.oneHot(3, 8f, 1f, array.getDataType()); ND: (4, 3) cpu() int32 [[ 1, 8, 1], [ 8, 1, 1], [ 1, 1, 8], [ 8, 1, 1], ]
oneHot
in interface NDArray
depth
- Depth of the one hot dimension.onValue
- The value assigned to the locations represented by indices.offValue
- The value assigned to the locations not represented by indices.dataType
- dataType of the output.NDArray
default NDArray batchDot(NDArray other)
NDArray
and the other NDArray
.
Examples
jshell> NDArray array1 = manager.ones(new Shape(2, 1, 4)); jshell> NDArray array2 = manager.ones(new Shape(2, 4, 6)); jshell> array1.batchDot(array2); ND: (2, 1, 6) cpu() float32 [[[4., 4., 4., 4., 4., 4.], ], [[4., 4., 4., 4., 4., 4.], ], ]
default ai.djl.ndarray.internal.NDArrayEx getNDArrayInternal()
NDArray
.
This method should only be used by Engine provider
getNDArrayInternal
in interface NDArray
NDArray