public abstract class NDArrayAdapter extends java.lang.Object implements 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 |
---|---|
protected NDManager |
alternativeManager |
protected DataType |
dataType |
protected boolean |
isClosed |
protected NDManager |
manager |
protected java.lang.String |
name |
protected Shape |
shape |
protected java.lang.String |
uid |
Modifier | Constructor and Description |
---|---|
protected |
NDArrayAdapter(NDManager manager,
NDManager alternativeManager,
Shape shape,
DataType dataType,
java.lang.String uid) |
Modifier and Type | Method and Description |
---|---|
NDArray |
abs()
Returns the absolute value of this
NDArray element-wise. |
NDArray |
acos()
Returns the inverse trigonometric cosine of this
NDArray element-wise. |
NDArray |
acosh()
Returns the inverse hyperbolic cosine of this
NDArray element-wise. |
NDArray |
add(NDArray other)
Adds other
NDArray s to this NDArray element-wise. |
NDArray |
add(java.lang.Number n)
Adds a number to this
NDArray element-wise. |
NDArray |
addi(NDArray other)
Adds other
NDArray s to this NDArray element-wise in place. |
NDArray |
addi(java.lang.Number n)
Adds a number to this
NDArray element-wise in place. |
NDArray |
argMax()
Returns the indices of the maximum values into the flattened
NDArray . |
NDArray |
argMax(int axis)
Returns the indices of the maximum values along given axis.
|
NDArray |
argMin()
Returns the indices of the minimum values into the flattened
NDArray . |
NDArray |
argMin(int axis)
Returns the indices of the minimum values along given axis.
|
NDArray |
argSort(int axis,
boolean ascending)
Returns the indices that would sort this
NDArray given the axis. |
NDArray |
asin()
Returns the inverse trigonometric sine of this
NDArray element-wise. |
NDArray |
asinh()
Returns the inverse hyperbolic sine of this
NDArray element-wise. |
NDArray |
atan()
Returns the inverse trigonometric tangent of this
NDArray element-wise. |
NDArray |
atanh()
Returns the inverse hyperbolic tangent of this
NDArray element-wise. |
void |
attach(NDManager manager)
Attaches this
NDResource to the specified NDManager . |
NDArray |
batchDot(NDArray other)
Batchwise product of this
NDArray and the other NDArray . |
NDArray |
booleanMask(NDArray index,
int axis)
Returns portion of this
NDArray given the index boolean NDArray along given
axis. |
NDArray |
broadcast(Shape shape)
Broadcasts this
NDArray to be the given shape. |
NDArray |
cbrt()
Returns the cube-root of this
NDArray element-wise. |
NDArray |
ceil()
Returns the ceiling of this
NDArray element-wise. |
NDArray |
clip(java.lang.Number min,
java.lang.Number max)
Clips (limit) the values in this
NDArray . |
void |
close() |
boolean |
contentEquals(NDArray other)
|
boolean |
contentEquals(java.lang.Number number)
Returns
true if all elements in this NDArray are equal to the Number . |
void |
copyTo(NDArray array)
Deep-copies the current
NDArray to the one passed in. |
NDArray |
cos()
Returns the trigonometric cosine of this
NDArray element-wise. |
NDArray |
cosh()
Returns the hyperbolic cosine of this
NDArray element-wise. |
NDArray |
cumSum()
Returns the cumulative sum of the elements in the flattened
NDArray . |
NDArray |
cumSum(int axis)
Return the cumulative sum of the elements along a given axis.
|
NDArray |
div(NDArray other)
Divides this
NDArray by the other NDArray element-wise. |
NDArray |
div(java.lang.Number n)
Divides this
NDArray by a number element-wise. |
NDArray |
divi(NDArray other)
Divides this
NDArray by the other NDArray element-wise in place. |
NDArray |
divi(java.lang.Number n)
Divides this
NDArray by a number element-wise in place. |
NDArray |
dot(NDArray other)
Dot product of this
NDArray and the other NDArray . |
NDArray |
eq(NDArray other)
Returns the boolean
NDArray for element-wise "Equals" comparison. |
NDArray |
eq(java.lang.Number n)
Returns the boolean
NDArray for element-wise "Equals" comparison. |
NDArray |
erfinv()
Returns element-wise inverse gauss error function of the
NDArray . |
NDArray |
exp()
Returns the exponential value of this
NDArray element-wise. |
NDArray |
expandDims(int axis)
Expands the
Shape of a NDArray . |
NDArray |
flatten()
Flattens this
NDArray into a 1-D NDArray in row-major order. |
NDArray |
flip(int... axes)
Returns the reverse order of elements in an array along the given axis.
|
NDArray |
floor()
Returns the floor of this
NDArray element-wise. |
DataType |
getDataType()
Returns the
DataType of this NDArray . |
Device |
getDevice()
Returns the
Device of this NDArray . |
NDArray |
getGradient()
Returns the gradient
NDArray attached to this NDArray . |
NDManager |
getManager()
Returns the
NDManager that manages this. |
java.lang.String |
getName()
Returns the name of this
NDArray . |
ai.djl.ndarray.internal.NDArrayEx |
getNDArrayInternal()
Returns an internal representative of Native
NDArray . |
Shape |
getShape()
Returns the
Shape of this NDArray . |
SparseFormat |
getSparseFormat()
Returns the
SparseFormat of this NDArray . |
java.lang.String |
getUid()
Returns unique identifier of this
NDArray . |
NDArray |
gt(NDArray other)
Returns the boolean
NDArray for element-wise "Greater Than" comparison. |
NDArray |
gt(java.lang.Number n)
Returns the boolean
NDArray for element-wise "Greater" comparison. |
NDArray |
gte(NDArray other)
Returns the boolean
NDArray for element-wise "Greater or equals" comparison. |
NDArray |
gte(java.lang.Number n)
Returns the boolean
NDArray for element-wise "Greater or equals" comparison. |
boolean |
hasGradient()
Returns true if the gradient calculation is required for this
NDArray . |
NDArray |
isInfinite()
Returns the boolean
NDArray with value true where this NDArray 's
entries are infinite, or false where they are not infinite. |
NDArray |
isNaN()
Returns the boolean
NDArray with value true where this NDArray 's
entries are NaN, or false where they are not NaN. |
NDArray |
log()
Returns the natural logarithmic value of this
NDArray element-wise. |
NDArray |
log10()
Returns the base 10 logarithm of this
NDArray element-wise. |
NDArray |
log2()
Returns the base 2 logarithm of this
NDArray element-wise. |
NDArray |
logicalAnd(NDArray other)
Returns the truth value of this
NDArray AND the other NDArray element-wise. |
NDArray |
logicalNot()
Computes the truth value of NOT this
NDArray element-wise. |
NDArray |
logicalOr(NDArray other)
Computes the truth value of this
NDArray OR the other NDArray element-wise. |
NDArray |
logicalXor(NDArray other)
Computes the truth value of this
NDArray XOR the other NDArray element-wise. |
NDArray |
logSoftmax(int axis)
Applies the softmax function followed by a logarithm.
|
NDArray |
lt(NDArray other)
Returns the boolean
NDArray for element-wise "Less" comparison. |
NDArray |
lt(java.lang.Number n)
Returns the boolean
NDArray for element-wise "Less" comparison. |
NDArray |
lte(NDArray other)
Returns the boolean
NDArray for element-wise "Less or equals" comparison. |
NDArray |
lte(java.lang.Number n)
Returns the boolean
NDArray for element-wise "Less or equals" comparison. |
NDArray |
matMul(NDArray other)
Product matrix of this
NDArray and the other NDArray . |
NDArray |
max()
Returns the maximum of this
NDArray . |
NDArray |
max(int[] axes,
boolean keepDims)
Returns the maximum of this
NDArray along given axes. |
NDArray |
maximum(NDArray other)
Returns the maximum of this
NDArray and the other NDArray element-wise. |
NDArray |
maximum(java.lang.Number n)
Returns the maximum of this
NDArray and a number element-wise. |
NDArray |
mean()
Returns the average of this
NDArray . |
NDArray |
mean(int[] axes,
boolean keepDims)
Returns the average of this
NDArray along given axes. |
NDArray |
median()
Returns median value for this
NDArray . |
NDArray |
median(int[] axes)
Returns median value along given axes.
|
NDArray |
min()
Returns the minimum of this
NDArray . |
NDArray |
min(int[] axes,
boolean keepDims)
Returns the minimum of this
NDArray along given axes. |
NDArray |
minimum(NDArray other)
Returns the minimum of this
NDArray and the other NDArray element-wise. |
NDArray |
minimum(java.lang.Number n)
Returns the minimum of this
NDArray and a number element-wise. |
NDArray |
mod(NDArray other)
Returns element-wise remainder of division.
|
NDArray |
mod(java.lang.Number n)
Returns element-wise remainder of division.
|
NDArray |
modi(NDArray other)
Returns in place element-wise remainder of division in place.
|
NDArray |
modi(java.lang.Number n)
Returns element-wise remainder of division in place.
|
NDArray |
mul(NDArray other)
Multiplies this
NDArray by other NDArray s element-wise. |
NDArray |
mul(java.lang.Number n)
Multiplies this
NDArray by a number element-wise. |
NDArray |
muli(NDArray other)
Multiplies this
NDArray by other NDArray element-wise in place. |
NDArray |
muli(java.lang.Number n)
Multiplies this
NDArray by a number element-wise in place. |
NDArray |
neg()
Returns the numerical negative
NDArray element-wise. |
NDArray |
negi()
Returns the numerical negative
NDArray element-wise in place. |
NDArray |
neq(NDArray other)
Returns the boolean
NDArray for element-wise "Not equals" comparison. |
NDArray |
neq(java.lang.Number n)
Returns the boolean
NDArray for element-wise "Not equals" comparison. |
NDArray |
nonzero()
Returns the indices of elements that are non-zero.
|
NDArray |
norm(boolean keepDims)
Returns the norm of this
NDArray . |
NDArray |
norm(int ord,
int[] axes,
boolean keepDims)
Returns the norm of this
NDArray . |
NDArray |
oneHot(int depth,
float onValue,
float offValue,
DataType dataType)
Returns a one-hot
NDArray . |
NDArray |
percentile(java.lang.Number percentile)
Returns percentile for this
NDArray . |
NDArray |
percentile(java.lang.Number percentile,
int[] axes)
Returns median along given dimension(s).
|
NDArray |
pow(NDArray other)
Takes the power of this
NDArray with the other NDArray element-wise. |
NDArray |
pow(java.lang.Number n)
Takes the power of this
NDArray with a number element-wise. |
NDArray |
powi(NDArray other)
Takes the power of this
NDArray with the other NDArray element-wise in place. |
NDArray |
powi(java.lang.Number n)
Takes the power of this
NDArray with a number element-wise in place. |
NDArray |
prod()
Returns the product of this
NDArray . |
NDArray |
prod(int[] axes,
boolean keepDims)
Returns the product of this
NDArray elements over the given axes. |
NDArray |
repeat(int axis,
long repeats)
Repeats element of this
NDArray the number of times given repeats along given axis. |
NDArray |
repeat(long repeats)
Repeats element of this
NDArray the number of times given repeats. |
NDArray |
repeat(long[] repeats)
Repeats element of this
NDArray the number of times given repeats along each axis. |
NDArray |
repeat(Shape desiredShape)
Repeats element of this
NDArray to match the desired shape. |
NDArray |
reshape(Shape shape)
Reshapes this
NDArray to the given Shape . |
NDArray |
rotate90(int times,
int[] axes)
Rotates an array by 90 degrees in the plane specified by axes.
|
NDArray |
round()
Returns the round of this
NDArray element-wise. |
NDArray |
sequenceMask(NDArray sequenceLength)
Sets all elements outside the sequence to 0.
|
NDArray |
sequenceMask(NDArray sequenceLength,
float value)
Sets all elements outside the sequence to a constant value.
|
void |
set(java.nio.Buffer data)
Sets this
NDArray value from Buffer . |
void |
set(NDArray index,
java.lang.Number value)
Sets the
NDArray by boolean mask. |
void |
set(NDIndex index,
java.util.function.Function<NDArray,NDArray> function)
Sets the specific index by a function.
|
void |
set(NDIndex index,
NDArray value)
Sets the specified index in this
NDArray with the given values. |
void |
set(NDIndex index,
java.lang.Number value)
Sets the specified index in this
NDArray with the given value. |
void |
setName(java.lang.String name)
Sets name of this
NDArray . |
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. |
void |
setScalar(NDIndex index,
java.lang.Number value)
Sets the specified scalar in this
NDArray with the given value. |
NDArray |
sign()
Returns the element-wise sign.
|
NDArray |
signi()
Returns the element-wise sign in-place.
|
NDArray |
sin()
Returns the trigonometric sine of this
NDArray element-wise. |
NDArray |
sinh()
Returns the hyperbolic sine of this
NDArray element-wise. |
NDArray |
softmax(int axis)
Applies the softmax function along the given axis.
|
NDArray |
sort()
Sorts the flattened
NDArray . |
NDArray |
sort(int axis)
Sorts the flattened
NDArray . |
NDList |
split(long[] indices,
int axis)
Splits this
NDArray into multiple sub-NDArray s given indices along given
axis. |
NDList |
split(long sections,
int axis)
Splits this
NDArray into multiple subNDArray s given sections along the given
axis. |
NDArray |
sqrt()
Returns the square root of this
NDArray element-wise. |
NDArray |
square()
Returns the square of this
NDArray element-wise. |
NDArray |
squeeze(int[] axes)
Removes singleton dimensions at the given axes.
|
NDArray |
stopGradient()
Returns an NDArray equal to this that stop gradient propagation through it.
|
NDArray |
sub(NDArray other)
Subtracts the other
NDArray from this NDArray element-wise. |
NDArray |
sub(java.lang.Number n)
Subtracts a number from this
NDArray element-wise. |
NDArray |
subi(NDArray other)
Subtracts the other
NDArray from this NDArray element-wise in place. |
NDArray |
subi(java.lang.Number n)
Subtracts a number from this
NDArray element-wise in place. |
NDArray |
sum()
Returns the sum of this
NDArray . |
NDArray |
sum(int[] axes,
boolean keepDims)
Returns the sum of this
NDArray along given axes. |
NDArray |
tan()
Returns the trigonometric tangent of this
NDArray element-wise. |
NDArray |
tanh()
Returns the hyperbolic tangent of this
NDArray element-wise. |
void |
tempAttach(NDManager manager)
Temporarily attaches this
NDResource to the specified NDManager . |
NDArray |
tile(int axis,
long repeats)
Constructs a
NDArray by repeating this NDArray the number of times given by
repeats along given axis. |
NDArray |
tile(long repeats)
Constructs a
NDArray by repeating this NDArray the number of times given
repeats. |
NDArray |
tile(long[] repeats)
Constructs a
NDArray by repeating this NDArray the number of times given by
repeats. |
NDArray |
tile(Shape desiredShape)
Constructs a
NDArray by repeating this NDArray the number of times to match
the desired shape. |
NDArray |
toDegrees()
Converts this
NDArray from radians to degrees element-wise. |
NDArray |
toDense()
Returns a dense representation of the sparse
NDArray . |
NDArray |
toDevice(Device device,
boolean copy)
Moves this
NDArray to a different Device . |
NDArray |
toRadians()
Converts this
NDArray from degrees to radians element-wise. |
NDArray |
toSparse(SparseFormat fmt)
Returns a sparse representation of
NDArray . |
java.lang.String |
toString() |
java.lang.String[] |
toStringArray(java.nio.charset.Charset charset)
Converts this
NDArray to a String array with the specified charset. |
NDArray |
toType(DataType dataType,
boolean copy)
Converts this
NDArray to a different DataType . |
NDArray |
trace(int offset,
int axis1,
int axis2)
Returns the sum along diagonals of this
NDArray . |
NDArray |
transpose()
Returns this
NDArray with axes transposed. |
NDArray |
transpose(int... axes)
Returns this
NDArray with given axes transposed. |
NDArray |
trunc()
Returns the truncated value of this
NDArray element-wise. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
all, allClose, allClose, any, argSort, argSort, booleanMask, broadcast, concat, concat, countNonzero, countNonzero, decode, duplicate, encode, get, get, get, get, getBoolean, getByte, getDouble, getFloat, getInt, getLong, getScalar, getUint8, intern, isEmpty, isScalar, isSparse, like, max, mean, min, none, norm, norm, norm, oneHot, oneHot, onesLike, prod, reshape, scaleGradient, set, set, set, set, set, shapeEquals, size, size, split, split, squeeze, squeeze, stack, stack, sum, swapAxes, toArray, toBooleanArray, toByteArray, toDebugString, toDebugString, toDoubleArray, toFloatArray, toIntArray, toLongArray, toStringArray, toUint8Array, trace, trace, zerosLike
detach
getAsBytes, getAsObject, getAsString, toByteBuffer, wrap, wrap, wrapAsJson
protected NDManager manager
protected NDManager alternativeManager
protected Shape shape
protected DataType dataType
protected java.lang.String name
protected boolean isClosed
protected java.lang.String uid
public NDManager getManager()
NDManager
that manages this.getManager
in interface NDResource
NDManager
that manages this.public 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 topublic void tempAttach(NDManager manager)
NDResource
to the specified NDManager
.
Attached resource will be returned to the original manager when the NDManager
is
closed.
tempAttach
in interface NDResource
manager
- the NDManager
to be attached topublic SparseFormat getSparseFormat()
SparseFormat
of this NDArray
.getSparseFormat
in interface NDArray
SparseFormat
of this NDArray
public java.lang.String getName()
NDArray
.public void setName(java.lang.String name)
NDArray
.public java.lang.String getUid()
NDArray
.public Device getDevice()
public 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
public Shape getShape()
public NDArray toDevice(Device device, boolean copy)
NDArray
to a different Device
.public NDArray toType(DataType dataType, boolean copy)
NDArray
to a different DataType
.public 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 notpublic NDArray getGradient()
NDArray
attached to this NDArray
.getGradient
in interface NDArray
NDArray
public boolean hasGradient()
NDArray
.hasGradient
in interface NDArray
NDArray
else falsepublic NDArray stopGradient()
stopGradient
in interface NDArray
public java.lang.String[] toStringArray(java.nio.charset.Charset charset)
NDArray
to a String array with the specified charset.
This method is only applicable to the String typed NDArray and not for printing purpose
toStringArray
in interface NDArray
charset
- to charset for the stringpublic void set(java.nio.Buffer data)
NDArray
value from Buffer
.public void set(NDIndex index, NDArray value)
NDArray
with the given values.public void set(NDIndex index, java.lang.Number value)
NDArray
with the given value.public void set(NDIndex index, java.util.function.Function<NDArray,NDArray> function)
public void set(NDArray index, java.lang.Number value)
NDArray
by boolean mask.public void setScalar(NDIndex index, java.lang.Number value)
NDArray
with the given value.public void copyTo(NDArray array)
NDArray
to the one passed in.public 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
public 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
public 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
public 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 comparepublic 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 comparepublic 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]
public 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]
public 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], ]
public 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], ]
public 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]
public 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]
public 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]
public 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]
public 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]
public 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]
public 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]
public 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]
public 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.]
public 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.], ]
public 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.]
public 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.], ]
public 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.]
public 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.], ]
public 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. ]
public 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], ]
public 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.]
public 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.]
public 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.]
public 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.], ]
public 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.]
public 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.]
public 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.]
public 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.], ]
public 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.]
public 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.], ]
public 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. ]
public 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], ]
public 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.]
public 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.]
public 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.]
public 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.], ]
public NDArray sign()
public NDArray signi()
public 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.]
public 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. ], ]
public 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.]
public 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. ], ]
public NDArray neg()
NDArray
element-wise.
jshell> NDArray array = manager.arange(5f); jshell> array.neg(); ND: (5) cpu() float32 [-0., -1., -2., -3., -4.]
public 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.]
public NDArray abs()
NDArray
element-wise.
Examples
jshell> NDArray array = manager.create(new float[] {-1f, -2f}); jshell> array.abs(); ND: (2) cpu() float32 [1., 2.]
public NDArray square()
NDArray
element-wise.
Examples
jshell> NDArray array = manager.create(new float[] {2f, -3f}); jshell> array.square(); ND: (2) cpu() float32 [4., 9.]
public NDArray sqrt()
NDArray
element-wise.
Examples
jshell> NDArray array = manager.create(new float[] {4f}); jshell> array.sqrt(); ND: (1) cpu() float32 [2., ]
public 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.]
public 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.]
public 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.]
public 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.]
public 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.]
public 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]
public 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]
public 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]
public 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]
public 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. ]
public 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],
public 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],
public 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. ]
public 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]
public 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]
public 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]
public 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 ]
public 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]
public 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]
public 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]
public 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]
public 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.]
public 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 ]
public 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
public 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.], ]
public 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
public 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.], ]
public 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.
public 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.], ]
public 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.
public 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.], ]
public 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
public 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], ]
public NDArray rotate90(int times, int[] axes)
Rotation direction is from the first towards the second axis.
public 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
public NDList split(long sections, int axis)
NDArray
into multiple subNDArray
s given sections along the 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(3, 1).forEach(System.out::println); ND: (2, 3) cpu() float32 [[ 0., 1., 2.], [ 9., 10., 11.], ] ND: (2, 3) cpu() float32 [[ 3., 4., 5.], [12., 13., 14.], ] ND: (2, 3) cpu() float32 [[ 6., 7., 8.], [15., 16., 17.], ]
public 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)
public 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.]
public 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.], ]
public 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
public 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.]
public 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
public 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]
public 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
public 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
public 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
public 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.], ]
public 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., 1.], [3., 4.], ]
public NDArray softmax(int axis)
softmax
in interface NDArray
axis
- the axis along which to applyNDArray
NDArray.softmax(int)
public 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
public 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.]
public 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.], ]
public 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 infinitepublic 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]
public 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.]
public 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.], ]
public 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.], ]
public 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.]
public 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.]
public 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.]
public 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.]
public 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.], ]
public 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.], ], ]
public 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.
public 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.]
public NDArray flip(int... axes)
The shape of the array is preserved, but the elements are reordered.
public 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.], ]
public 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.], ], ]
public 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.], ], ]
public 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.
public 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]
public 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.
public 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]
public NDArray percentile(java.lang.Number percentile)
NDArray
.percentile
in interface NDArray
percentile
- the target percentile in range of 0..100NDArray
public 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
NDArraypublic NDArray median()
NDArray
.public NDArray median(int[] axes)
public NDArray toDense()
NDArray
.public NDArray toSparse(SparseFormat fmt)
NDArray
.toSparse
in interface NDArray
fmt
- the SparseFormat
of this NDArray
NDArray
public 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], ]
public 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]
public 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], ]
public 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
public 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
public 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.], ], ]
public ai.djl.ndarray.internal.NDArrayEx getNDArrayInternal()
NDArray
.
This method should only be used by Engine provider
getNDArrayInternal
in interface NDArray
NDArray
public void close()
close
in interface NDArray
close
in interface NDResource
close
in interface java.lang.AutoCloseable
public java.lang.String toString()
toString
in class java.lang.Object