Class NDArrays
-
Method Summary
Modifier and TypeMethodDescriptionstatic NDArray
static NDArray
Adds a number to theNDArray
element-wise.static NDArray
Adds aNDArray
to a number element-wise.static NDArray
Adds all of theNDArray
s together element-wise in place.static NDArray
Adds a number to theNDArray
element-wise in place.static NDArray
Adds aNDArray
to a number element-wise in place.static boolean
Returnstrue
if twoNDArray
are element-wise equal within a tolerance.static boolean
Returnstrue
if twoNDArray
are element-wise equal within a tolerance.static NDArray
booleanMask
(NDArray data, NDArray index) static NDArray
booleanMask
(NDArray data, NDArray index, int axis) static NDArray
Joins aNDList
along the first axis.static NDArray
Joins aNDList
along an existing axis.static boolean
contentEquals
(NDArray a, NDArray b) static boolean
contentEquals
(NDArray a, Number n) static NDArray
static NDArray
Divides theNDArray
by a number element-wise.static NDArray
Divides a number by aNDArray
element-wise.static NDArray
static NDArray
Divides a number by aNDArray
element-wise in place.static NDArray
Divides a number by aNDArray
element-wise.static NDArray
static NDArray
Returns the booleanNDArray
for element-wise "Equals" comparison.static NDArray
Returns the booleanNDArray
for element-wise "Equals" comparison.static NDArray
Returns the booleanNDArray
for element-wise "Equals" comparison.static NDArray
Returns element-wise gauss error function of theNDArray
.static NDArray
Returns element-wise inverse gauss error function of the inputNDArray
.static NDArray
Returns the booleanNDArray
for element-wise "Greater Than" comparison.static NDArray
Returns the booleanNDArray
for element-wise "Greater Than" comparison.static NDArray
Returns the booleanNDArray
for element-wise "Greater Than" comparison.static NDArray
Returns the booleanNDArray
for element-wise "Greater or equals" comparison.static NDArray
Returns the booleanNDArray
for element-wise "Greater or equals" comparison.static NDArray
Returns the booleanNDArray
for element-wise "Greater or equals" comparison.static NDArray
logicalAnd
(NDArray a, NDArray b) static NDArray
static NDArray
logicalXor
(NDArray a, NDArray b) static NDArray
Returns the booleanNDArray
for element-wise "Less" comparison.static NDArray
Returns the booleanNDArray
for element-wise "Less" comparison.static NDArray
Returns the booleanNDArray
for element-wise "Less" comparison.static NDArray
Returns the booleanNDArray
for element-wise "Less or equals" comparison.static NDArray
Returns the booleanNDArray
for element-wise "Less or equals" comparison.static NDArray
Returns the booleanNDArray
for element-wise "Less or equals" comparison.static NDArray
Product matrix of thisNDArray
and the otherNDArray
.static NDArray
static NDArray
Returns the maximum of aNDArray
and a number element-wise.static NDArray
Returns the maximum of a number and aNDArray
element-wise.static NDArray
static NDArray
Returns the minimum of aNDArray
and a number element-wise.static NDArray
Returns the minimum of a number and aNDArray
element-wise.static NDArray
Returns element-wise remainder of division.static NDArray
Returns element-wise remainder of division.static NDArray
Returns element-wise remainder of division.static NDArray
Returns element-wise remainder of division.static NDArray
Returns element-wise remainder of division in place.static NDArray
Returns element-wise remainder of division in place.static NDArray
Multiplies all of theNDArray
s together element-wise.static NDArray
Multiplies theNDArray
by a number element-wise.static NDArray
Multiplies a number by aNDArray
element-wise.static NDArray
Multiplies all of theNDArray
s together element-wise in place.static NDArray
Multiplies theNDArray
by a number element-wise in place.static NDArray
Multiplies a number by aNDArray
element-wise.static NDArray
Returns the booleanNDArray
for element-wise "Not equals" comparison.static NDArray
Returns the booleanNDArray
for element-wise "Not equals" comparison.static NDArray
Returns the booleanNDArray
for element-wise "Not equals" comparison.static NDArray
static NDArray
Takes the power of theNDArray
with a number element-wise.static NDArray
Takes the power of a number with aNDArray
element-wise.static NDArray
static NDArray
Takes the power of theNDArray
with a number element-wise in place.static NDArray
Takes the power of a number with aNDArray
element-wise in place.static NDArray
sequenceMask
(NDArray data, NDArray sequenceLength) static NDArray
sequenceMask
(NDArray data, NDArray sequenceLength, float value) static boolean
shapeEquals
(NDArray a, NDArray b) Checks 2NDArray
s for equal shapes.static NDArray
static NDArray
static NDArray
static NDArray
Subtracts a number from theNDArray
element-wise.static NDArray
Subtracts aNDArray
from a number element-wise.static NDArray
static NDArray
Subtracts a number from theNDArray
element-wise in place.static NDArray
Subtracts aNDArray
from a number element-wise in place.static NDArray
-
Method Details
-
contentEquals
Returnstrue
if all elements inNDArray
a are equal toNDArray
b.Examples
jshell> NDArray array = manager.ones(new Shape(3)); jshell> NDArrays.contentEquals(array, 1); // return true instead of boolean NDArray true
- Parameters:
a
- theNDArray
to comparen
- the number to compare- Returns:
- the boolean result
-
contentEquals
Returnstrue
if all elements inNDArray
a are equal toNDArray
b.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> NDArrays.contentEquals(array1, array2); // return true instead of boolean NDArray true
-
shapeEquals
Checks 2NDArray
s for equal shapes.Shapes are considered equal if:
Examples
jshell> NDArray array1 = manager.ones(new Shape(1, 2, 3)); jshell> NDArray array2 = manager.create(new Shape(1, 2, 3)); jshell> NDArrays.shapeEquals(array1, array2); // return true instead of boolean NDArray true
-
allClose
Returnstrue
if twoNDArray
are element-wise equal within a tolerance.Examples
jshell> NDArray array1 = manager.create(new double[] {1e10,1e-7}); jshell> NDArray array2 = manager.create(new double[] {1.00001e10,1e-8}); jshell> NDArrays.allClose(array1, array2); // return false instead of boolean NDArray false jshell> NDArray array1 = manager.create(new double[] {1e10,1e-8}); jshell> NDArray array2 = manager.create(new double[] {1.00001e10,1e-9}); jshell> NDArrays.allClose(array1, array2); // return true instead of boolean NDArray true
-
allClose
Returnstrue
if twoNDArray
are element-wise equal within a tolerance.Examples
jshell> NDArray array1 = manager.create(new double[] {1e10, 1e-7}); jshell> NDArray array2 = manager.create(new double[] {1.00001e10, 1e-8}); jshell> NDArrays.allClose(array1, array2, 1e-05, 1e-08, false); // return false instead of boolean NDArray false jshell> NDArray array1 = manager.create(new double[] {1e10, 1e-8}); jshell> NDArray array2 = manager.create(new double[] {1.00001e10, 1e-9}); jshell> NDArrays.allClose(array1, array2, 1e-05, 1e-08, false); // return true instead of boolean NDArray true jshell> NDArray array1 = manager.create(new float[] {1f, Float.NaN}); jshell> NDArray array2 = manager.create(new float[] {1f, Float.NaN}); jshell> NDArrays.allClose(array1, array2, 1e-05, 1e-08, true); // return true instead of boolean NDArray true
- Parameters:
a
- theNDArray
to compare withb
- theNDArray
to compare withrtol
- the relative tolerance parameteratol
- the absolute tolerance parameterequalNan
- whether to compare NaN’s as equal. Iftrue
, NaN’s in theNDArray
will be considered equal to NaN’s in the otherNDArray
- Returns:
- the boolean result
-
eq
Returns the booleanNDArray
for element-wise "Equals" comparison.Examples
jshell> NDArray array = manager.ones(new Shape(1)); jshell> NDArrays.eq(array, 1); ND: (1) cpu() boolean [ true]
-
eq
Returns the booleanNDArray
for element-wise "Equals" comparison.Examples
jshell> NDArray array = manager.ones(new Shape(1)); jshell> NDArrays.eq(1, array); ND: (1) cpu() boolean [ true]
-
eq
Returns the booleanNDArray
for element-wise "Equals" comparison.Examples
jshell> NDArray array1 = manager.create(new float[] {0f, 1f, 3f}); jshell> NDArray array2 = manager.arange(3f); jshell> NDArrays.eq(array1, array2); ND: (3) cpu() boolean [ true, true, false]
-
neq
Returns the booleanNDArray
for element-wise "Not equals" comparison.Examples
jshell> NDArray array = manager.arange(4f).reshape(2, 2); jshell> NDArrays.neq(array, 1); ND: (2, 2) cpu() boolean [[ true, false], [ true, true], ]
-
neq
Returns the booleanNDArray
for element-wise "Not equals" comparison.Examples
jshell> NDArray array = manager.arange(f4).reshape(2, 2); jshell> NDArrays.neq(1, array); ND: (2, 2) cpu() boolean [[ true, false], [ true, true], ]
-
neq
Returns the booleanNDArray
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> NDArrays.neq(array1, 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> NDArrays.neq(array1, array2); // broadcasting ND: (2, 2) cpu() boolean [[false, true], [false, true], ]
-
gt
Returns the booleanNDArray
for element-wise "Greater Than" comparison.Examples
jshell> NDArray array = manager.create(new float[] {4f, 2f}); jshell> NDArrays.gt(array, 2f); ND: (2) cpu() boolean [ true, false]
-
gt
Returns the booleanNDArray
for element-wise "Greater Than" comparison.Examples
jshell> NDArray array = manager.create(new float[] {4f, 2f}); jshell> NDArrays.gt(2f, array); ND: (2) cpu() boolean [false, false]
- Parameters:
n
- the number to be compareda
- the NDArray to be compared against- Returns:
- the boolean
NDArray
for element-wise "Greater Than" comparison
-
gt
Returns the booleanNDArray
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> NDArrays.gt(array1, array2); ND: (2) cpu() boolean [ true, false]
-
gte
Returns the booleanNDArray
for element-wise "Greater or equals" comparison.Examples
jshell> NDArray array = manager.create(new float[] {4f, 2f}); jshell> NDArrays.gte(array, 2); ND: (2) cpu() boolean [ true, true]
-
gte
Returns the booleanNDArray
for element-wise "Greater or equals" comparison.Examples
jshell> NDArray array = manager.create(new float[] {4f, 2f}); jshell> NDArrays.gte(2, array); ND: (2) cpu() boolean [false, true]
-
gte
Returns the booleanNDArray
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> NDArrays.gte(array1, array2); ND: (2) cpu() boolean [ true, true]
-
lt
Returns the booleanNDArray
for element-wise "Less" comparison.Examples
jshell> NDArray array = manager.create(new float[] {1f, 2f}); jshell> NDArrays.lt(array, 2f); ND: (2) cpu() boolean [ true, false]
-
lt
Returns the booleanNDArray
for element-wise "Less" comparison.Examples
jshell> NDArray array = manager.create(new float[] {1f, 2f}); jshell> NDArrays.lt(2f, array); ND: (2) cpu() boolean [false, false]
-
lt
Returns the booleanNDArray
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> NDArrays.lt(array1, array2); ND: (2) cpu() boolean [ true, false]
-
lte
Returns the booleanNDArray
for element-wise "Less or equals" comparison.Examples
jshell> NDArray array = manager.create(new float[] {1f, 2f}); jshell> NDArrays.lte(array, 2f); ND: (2) cpu() boolean [ true, true]
-
lte
Returns the booleanNDArray
for element-wise "Less or equals" comparison.Examples
jshell> NDArray array = manager.create(new float[] {1f, 2f}); jshell> NDArrays.lte(2f, array); ND: (2) cpu() boolean [false, true]
-
lte
Returns the booleanNDArray
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> NDArrays.lte(array1, array2) ND: (2) cpu() boolean [ true, true]
-
where
Returns elements chosen from theNDArray
or the otherNDArray
depending on condition.Given three
NDArray
s, condition, a, and b, returns anNDArray
with the elements from a or b, depending on whether the elements from conditionNDArray
aretrue
orfalse
. If condition has the same shape as a, each element in the outputNDArray
is from this if the corresponding element in the condition istrue
, and from other iffalse
.Note that all non-zero values are interpreted as
true
in conditionNDArray
.Examples
jshell> NDArray array = manager.arange(10f); jshell> NDArrays.where(array.lt(5), array, array.mul(10)); ND: (10) cpu() float32 [ 0., 1., 2., 3., 4., 50., 60., 70., 80., 90.] jshell> NDArray array = manager.create(new float[]{0f, 1f, 2f, 0f, 2f, 4f, 0f, 3f, 6f}, new Shape(3, 3)); jshell> NDArrays.where(array.lt(4), array, manager.create(-1f)); ND: (3, 3) cpu() float32 [[ 0., 1., 2.], [ 0., 2., -1.], [ 0., 3., -1.], ]
-
maximum
Returns the maximum of aNDArray
and a number element-wise.Examples
jshell> NDArray array = manager.create(new float[] {2f, 3f, 4f}); jshell> NDArrays.maximum(array, 3f); ND: (3) cpu() float32 [3., 3., 4.]
-
maximum
Returns the maximum of a number and aNDArray
element-wise.Examples
jshell> NDArray array = manager.create(new float[] {2f, 3f, 4f}); jshell> NDArrays.maximum(3f, array); ND: (3) cpu() float32 [3., 3., 4.]
-
maximum
Returns the maximum ofNDArray
a andNDArray
b element-wise.The shapes of
NDArray
a andNDArray
b 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> NDArrays.maximum(array1, 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> NDArrays.maximum(array1, array2); // broadcasting ND: (2, 2) cpu() float32 [[1. , 2. ], [0.5, 2. ], ]
-
minimum
Returns the minimum of aNDArray
and a number element-wise.Examples
jshell> NDArray array = manager.create(new float[] {2f, 3f, 4f}); jshell> NDArrays.minimum(array, 3f); ND: (3) cpu() float32 [2., 3., 3.]
-
minimum
Returns the minimum of a number and aNDArray
element-wise.Examples
jshell> NDArray array = manager.create(new float[] {2f, 3f, 4f}); jshell> NDArrays.minimum(3f, array); ND: (3) cpu() float32 [2., 3., 3.]
-
minimum
Returns the minimum ofNDArray
a andNDArray
b element-wise.The shapes of
NDArray
a andNDArray
b 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> NDArrays.minimum(array1, 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> NDArrays.minimum(array1, array2); // broadcasting ND: (2, 2) cpu() float32 [[0.5, 0. ], [0. , 1. ], ]
-
booleanMask
Returns portion of theNDArray
given the index booleanNDArray
along first axis.Examples
jshell> NDArray array = manager.create(new float[] {1f, 2f, 3f, 4f, 5f, 6f}, new Shape(3, 2)); jshell> NDArray mask = manager.create(new boolean[] {true, false, true}); jshell> NDArrays.booleanMask(array, mask); ND: (2, 2) cpu() float32 [[1., 2.], [5., 6.], ]
-
booleanMask
-
sequenceMask
Sets all elements of the givenNDArray
outside the sequenceNDArray
to a constant 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.sequenceLength
should be an input array of positive ints of dimension [batch_size]. -
sequenceMask
Sets all elements of the givenNDArray
outside the sequenceNDArray
to 0.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.sequenceLength
should be an input array of positive ints of dimension [batch_size]. -
add
Adds a number to theNDArray
element-wise.Examples
jshell> NDArray array = manager.create(new float[] {1f, 2f}); jshell> NDArrays.add(array, 2f); ND: (2) cpu() float32 [3., 4.]
-
add
Adds aNDArray
to a number element-wise.Examples
jshell> NDArray array = manager.create(new float[] {1f, 2f}); jshell> NDArrays.add(2f, array); ND: (2) cpu() float32 [3., 4.]
-
add
Adds aNDArray
to aNDArray
element-wise.The shapes of all of the
NDArray
s must be the same.Examples
jshell> NDArray array = manager.create(new float[] {1f, 2f}); jshell> NDArrays.add(array, array, array); ND: (2) cpu() float32 [3., 6.]
- Parameters:
arrays
- theNDArray
s to add together- Returns:
- the result
NDArray
- Throws:
IllegalArgumentException
- arrays must have at least two elementsIllegalArgumentException
- the shape of all inputs must be the same
-
sub
Subtracts a number from theNDArray
element-wise.Examples
jshell> NDArray array = manager.create(new float[] {1f, 2f}); jshell> array.sub(2f); ND: (2) cpu() float32 [-1., 0.]
-
sub
Subtracts aNDArray
from a number element-wise.Examples
jshell> NDArray array = manager.create(new float[] {1f, 2f}); jshell> NDArrays.sub(3f, array); ND: (2) cpu() float32 [2., 1.]
-
sub
Subtracts aNDArray
from aNDArray
element-wise.The shapes of
NDArray
a andNDArray
b must be broadcastable.Examples
jshell> NDArray array1 = manager.arange(9f).reshape(3, 3); jshell> NDArray array2 = manager.arange(3f); jshell> NDArrays.sub(array1, array2); // broadcasting ND: (3, 3) cpu() float32 [[0., 0., 0.], [3., 3., 3.], [6., 6., 6.], ]
-
mul
Multiplies theNDArray
by a number element-wise.Examples
jshell> NDArray array = manager.create(new float[] {1f, 2f}); jshell> NDArrays.mul(array, 3f); ND: (2) cpu() float32 [3., 6.]
- Parameters:
a
- the NDArray to be multipliedn
- the number to multiply by- Returns:
- the result
NDArray
-
mul
Multiplies a number by aNDArray
element-wise.Examples
jshell> NDArray array = manager.create(new float[] {1f, 2f}); jshell> NDArrays.mul(3f, array); ND: (2) cpu() float32 [3., 6.]
-
mul
Multiplies all of theNDArray
s together element-wise.The shapes of all of the
NDArray
s must be the same.Examples
jshell> NDArray array = manager.create(new float[] {1f, 2f}); jshell> NDArrays.mul(array, array, array); ND: (2) cpu() float32 [1., 8.]
- Parameters:
arrays
- theNDArray
s to multiply together- Returns:
- the result
NDArray
- Throws:
IllegalArgumentException
- arrays must have at least two elementsIllegalArgumentException
- the shape of all inputs must be the same
-
div
Divides theNDArray
by a number element-wise.Examples
jshell> NDArray array = manager.arange(5f); jshell> NDArrays.div(array, 4f); ND: (5) cpu() float32 [0. , 0.25, 0.5 , 0.75, 1. ]
-
div
Divides a number by aNDArray
element-wise.Examples
jshell> NDArray array = manager.arange(5f).add(1); jshell> NDArrays.div(4f, array); ND: (5) cpu() float32 [4. , 2. , 1.3333, 1. , 0.8 ]
-
div
Divides aNDArray
by aNDArray
element-wise.The shapes of
NDArray
a andNDArray
b must be broadcastable.Examples
jshell> NDArray array1 = manager.arange(9f).reshape(3, 3); jshell> NDArray array2 = manager.ones(new Shape(3)).mul(10); jshell> NDArrays.div(array1, array2); // broadcasting ND: (3, 3) cpu() float32 [[0. , 0.1, 0.2], [0.3, 0.4, 0.5], [0.6, 0.7, 0.8], ]
-
mod
Returns element-wise remainder of division.Examples
jshell> NDArray array = manager.arange(7f); jshell> NDArrays.mod(array, 5f); ND: (7) cpu() float32 [0., 1., 2., 3., 4., 0., 1.]
-
mod
Returns element-wise remainder of division.Examples
jshell> NDArray array = manager.arange(7f).add(1); jshell> NDArrays.mod(5f, array); ND: (7) cpu() float32 [0., 1., 2., 1., 0., 5., 5.]
-
mod
Returns element-wise remainder of division.Examples
jshell> NDArray array1 = manager.create(new float[] {4f, 7f}); jshell> NDArray array2 = manager.create(new float[] {2f, 3f}); jshell> NDArrays.mod(array1, array2); ND: (2) cpu() float32 [0., 1.]
- Parameters:
a
- the dividend NDArrayb
- the dividend NDArray- Returns:
- the result
NDArray
-
pow
Takes the power of theNDArray
with a number element-wise.Examples
jshell> NDArray array = manager.arange(5f); jshell> NDArrays.pow(array, 4f); ND: (6) cpu() float32 [ 0., 1., 8., 27., 64., 125.]
-
pow
Takes the power of a number with aNDArray
element-wise.Examples
jshell> NDArray array = manager.arange(5f); jshell> NDArrays.pow(4f, array); ND: (5) cpu() float32 [ 1., 4., 16., 64., 256.]
-
pow
Takes the power of aNDArray
with aNDArray
element-wise.The shapes of
NDArray
a andNDArray
b must be broadcastable.Examples
jshell> NDArray array1 = manager.arange(6f).reshape(3, 2); jshell> NDArray array2 = manager.create(new float[] {2f, 3f}); jshell> NDArrays.pow(array1, array2); // broadcasting ND: (3, 2) cpu() float32 [[ 0., 1.], [ 4., 27.], [ 16., 125.], ]
-
addi
Adds a number to theNDArray
element-wise in place.Examples
jshell> NDArray array = manager.create(new float[] {1f, 2f}); jshell> NDArrays.addi(array, 2f); ND: (2) cpu() float32 [3., 4.] jshell> array; ND: (2) cpu() float32 [3., 4.]
-
addi
Adds aNDArray
to a number element-wise in place.Examples
jshell> NDArray array = manager.create(new float[] {1f, 2f}); jshell> NDArrays.addi(2f, array); ND: (2) cpu() float32 [3., 4.] jshell> array; ND: (2) cpu() float32 [3., 4.]
-
addi
Adds all of theNDArray
s together element-wise in place.The shapes of all of the
NDArray
s must be the same.Examples
jshell> NDArray array1 = manager.create(new float[] {1f, 2f}); jshell> NDArray array2 = manager.create(new float[] {3f, 4f}); jshell> NDArray array3 = manager.create(new float[] {5f, 6f}); jshell> NDArrays.addi(array1, array2, array3); ND: (2) cpu() float32 [9., 12.] jshell> array; ND: (2) cpu() float32 [9., 12.]
- Parameters:
arrays
- theNDArray
s to add together- Returns:
- the result
NDArray
- Throws:
IllegalArgumentException
- arrays must have at least two elements
-
subi
Subtracts a number from theNDArray
element-wise in place.Examples
jshell> NDArray array = manager.create(new float[] {1f, 2f}); jshell> NDArrays.subi(array, 2f); ND: (2) cpu() float32 [-1., 0.] jshell> array; ND: (2) cpu() float32 [-1., 0.]
-
subi
Subtracts aNDArray
from a number element-wise in place.Examples
jshell> NDArray array = manager.create(new float[] {1f, 2f}); jshell> NDArrays.subi(3f, array); ND: (2) cpu() float32 [2., 1.] jshell> array; ND: (2) cpu() float32 [2., 1.]
-
subi
Subtracts aNDArray
from aNDArray
element-wise in place.The shapes of
NDArray
a andNDArray
b must be broadcastable.Examples
jshell> NDArray array1 = manager.arange(9f).reshape(3, 3); jshell> NDArray array2 = manager.arange(3f); jshell> NDArrays.subi(array1, 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.], ]
-
muli
Multiplies theNDArray
by a number element-wise in place.Examples
jshell> NDArray array = manager.create(new float[] {1f, 2f}); jshell> NDArrays.muli(array, 3f); ND: (2) cpu() float32 [3., 6.] jshell> array; ND: (2) cpu() float32 [3., 6.]
- Parameters:
a
- the NDArray to be multipliedn
- the number to multiply by- Returns:
- the result
NDArray
-
muli
Multiplies a number by aNDArray
element-wise.Examples
jshell> NDArray array = manager.create(new float[] {1f, 2f}); jshell> NDArrays.muli(3f, array); ND: (2) cpu() float32 [3., 6.] jshell> array; ND: (2) cpu() float32 [3., 6.]
-
muli
Multiplies all of theNDArray
s together element-wise in place.The shapes of all of the
NDArray
s must be the same.Examples
jshell> NDArray array1 = manager.create(new float[] {1f, 2f}); jshell> NDArray array2 = manager.create(new float[] {3f, 4f}); jshell> NDArray array3 = manager.create(new float[] {5f, 6f}); jshell> NDArrays.muli(array1, array2, array3); ND: (2) cpu() float32 [15., 48.] jshell> array; ND: (2) cpu() float32 [15., 48.]
- Parameters:
arrays
- theNDArray
s to multiply together- Returns:
- the result
NDArray
- Throws:
IllegalArgumentException
- arrays must have at least two elements
-
divi
Divides a number by aNDArray
element-wise in place.Examples
jshell> NDArray array = manager.arange(5f); jshell> NDArrays.divi(array, 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. ]
-
divi
Divides a number by aNDArray
element-wise.Examples
jshell> NDArray array = manager.arange(5f).add(1); jshell> NDArrays.divi(4f, array); ND: (5) cpu() float32 [4. , 2. , 1.3333, 1. , 0.8 ] jshell> array; ND: (5) cpu() float32 [4. , 2. , 1.3333, 1. , 0.8 ]
-
divi
Divides aNDArray
by aNDArray
element-wise.The shapes of
NDArray
a andNDArray
b must be broadcastable.Examples
jshell> NDArray array1 = manager.arange(9f).reshape(3, 3); jshell> NDArray array2 = manager.ones(new Shape(3)).mul(10); jshell> NDArrays.divi(array1, 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], ]
-
modi
Returns element-wise remainder of division in place.Examples
jshell> NDArray array = manager.arange(7f); jshell> NDArrays.modi(array, 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.]
-
modi
Returns element-wise remainder of division in place.Examples
jshell> NDArray array = manager.arange(7f); jshell> NDArrays.modi(5f, array); ND: (7) cpu() float32 [0., 0., 1., 2., 1., 0., 5.] jshell> array; ND: (7) cpu() float32 [0., 0., 1., 2., 1., 0., 5.]
-
modi
Returns element-wise remainder of division.Examples
jshell> NDArray array1 = manager.create(new float[] {4f, 7f}); jshell> NDArray array2 = manager.create(new float[] {2f, 3f}); jshell> NDArrays.modi(array1, array2); ND: (2) cpu() float32 [0., 1.] jshell> array1; ND: (2) cpu() float32 [0., 1.]
- Parameters:
a
- the dividend NDArrayb
- the dividend NDArray- Returns:
- the result
NDArray
-
powi
Takes the power of theNDArray
with a number element-wise in place.Examples
jshell> NDArray array = manager.arange(5f); jshell> NDArrays.powi(array, 4f); ND: (6) cpu() float32 [ 0., 1., 8., 27., 64., 125.] jshell> array; ND: (6) cpu() float32 [ 0., 1., 8., 27., 64., 125.]
-
powi
Takes the power of a number with aNDArray
element-wise in place.Examples
jshell> NDArray array = manager.arange(5f); jshell> NDArrays.powi(4f, array); ND: (5) cpu() float32 [ 1., 4., 16., 64., 256.] jshell> array; ND: (5) cpu() float32 [ 1., 4., 16., 64., 256.]
-
powi
Takes the power of aNDArray
with aNDArray
element-wise.The shapes of
NDArray
a andNDArray
b must be broadcastable.Examples
jshell> NDArray array1 = manager.arange(6f).reshape(3, 2); jshell> NDArray array2 = manager.create(new float[] {2f, 3f}); jshell> NDArrays.powi(array1, 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.], ]
-
dot
Dot product ofNDArray
a andNDArray
b.- If both the
NDArray
and the otherNDArray
are 1-DNDArray
s, it is inner product of vectors (without complex conjugation). - If both the
NDArray
and the otherNDArray
are 2-DNDArray
s, it is matrix multiplication. - If either the
NDArray
or the otherNDArray
is 0-DNDArray
(scalar), it is equivalent to mul. - If the
NDArray
is N-DNDArray
and the otherNDArray
is 1-DNDArray
, it is a sum product over the last axis of those. - If the
NDArray
is N-DNDArray
and the otherNDArray
is M-DNDArray
(where M>=2), it is a sum product over the last axis of thisNDArray
and the second-to-last axis of the otherNDArray
Examples
jshell> NDArray array1 = manager.create(new float[] {1f, 2f, 3f}); jshell> NDArray array2 = manager.create(new float[] {4f, 5f, 6f}); jshell> NDArrays.dot(array1, 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> NDArrays.dot(array1, 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> NDArrays.dot(array1, 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> NDArrays.dot(array1, 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> NDArrays.dot(array1, array2); ND: (2, 2, 2) cpu() float32 [[[ 7., 10.], [15., 22.], ], [[23., 34.], [31., 46.], ], ]
- If both the
-
matMul
Product matrix of thisNDArray
and the otherNDArray
.The behavior depends on the arguments in the following way.
- If both this
NDArray
and the otherNDArray
are 2-DNDArray
s, they are multiplied like conventional matrices - If either this
NDArray
or the otherNDArray
is N-DNDArray
, N > 2 , it is treated as a stack of matrices residing in the last two indexes and broadcast accordingly. - If this
NDArray
is 1-DNDArray
, it is promoted to a matrix by prepending a 1 to its dimensions. After matrix multiplication the prepended 1 is removed. - If other
NDArray
is 1-DNDArray
, 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> NDArrays.matMul(array1, 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> NDArrays.matMul(array1, 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> NDArrays.matMul(array1, 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> NDArrays.matMul(array1, array2); ND: () cpu() float32 98.
- If both this
-
stack
Joins a sequence ofNDArray
s inNDList
along the first axis.Examples
jshell> NDArray array1 = manager.create(new float[] {0f, 1f, 2f}); jshell> NDArray array2 = manager.create(new float[] {3f, 4f, 5f}); jshell> NDArray array3 = manager.create(new float[] {6f, 7f, 8f}); jshell> NDArrays.stack(new NDList(array1, array2, array3)); ND: (3, 3) cpu() float32 [[0., 1., 2.], [3., 4., 5.], [6., 7., 8.], ]
-
stack
Joins a sequence ofNDArray
s inNDList
along a new axis.The axis parameter specifies the index of the new axis in the dimensions of the result. For example, if axis=0 it will be the first dimension and if axis=-1 it will be the last dimension.
Examples
jshell> NDArray array1 = manager.create(new float[] {0f, 1f, 2f}); jshell> NDArray array2 = manager.create(new float[] {3f, 4f, 5f}); jshell> NDArrays.stack(new NDList(array1, array2), 0); ND: (2, 3) cpu() float32 [[0., 1., 2.], [3., 4., 5.], ] jshell> NDArray array1 = manager.create(new float[] {0f, 1f, 2f}); jshell> NDArray array2 = manager.create(new float[] {3f, 4f, 5f}); jshell> NDArrays.stack(new NDList(array1, array2), 1); ND: (3, 2) cpu() float32 [[0., 3.], [1., 4.], [2., 5.], ]
-
concat
Joins aNDList
along the first axis.Examples
jshell> NDArray array1 = manager.create(new float[] {0f, 1f, 2f}); jshell> NDArray array2 = manager.create(new float[] {3f, 4f, 5f}); jshell> NDArray array3 = manager.create(new float[] {6f, 7f, 8f}); jshell> NDArrays.concat(new NDList(array1, array2, array3)); ND: (9) cpu() float32 [0., 1., 2., 3., 4., 5., 6., 7., 8.]
-
concat
Joins aNDList
along an existing axis.Examples
jshell> NDArray array1 = manager.create(new float[] {1f, 2f, 3f, 4f}, new Shape(2, 2)); jshell> NDArray array2 = manager.create(new float[] {5f, 6f}, new Shape(1, 2)); jshell> NDArrays.concat(new NDList(array1, array2), 0); ND: (3, 2) cpu() float32 [[1., 2.], [3., 4.], [5., 6.], ] jshell> NDArrays.concat(new NDList(array1, array2.transpose()), 1); ND: (2, 3) cpu() float32 [[1., 2., 5.], [3., 4., 6.], ]
-
logicalAnd
Returns the truth value ofNDArray
a ANDNDArray
b element-wise.The shapes of
NDArray
a andNDArray
b must be broadcastable.Examples
jshell> NDArray array1 = manager.create(new boolean[] {true}); jshell> NDArray array2 = manager.create(new boolean[] {false}); jshell> NDArrays.logicalAnd(array1, array2); ND: (1) cpu() boolean [false] jshell> array1 = manager.create(new boolean[] {true, false}); jshell> array2 = manager.create(new boolean[] {false, false}); jshell> NDArrays.logicalAnd(array.gt(1), array.lt(4)); ND: (2) cpu() boolean [false, false]
-
logicalOr
Computes the truth value ofNDArray
a ANDNDArray
b element-wise.Examples
jshell> NDArray array1 = manager.create(new boolean[] {true}); jshell> NDArray array2 = manager.create(new boolean[] {false}); jshell> NDArrays.logicalOr(array1, array2); ND: (1) cpu() boolean [ true] jshell> array1 = manager.create(new boolean[] {true, false}); jshell> array2 = manager.create(new boolean[] {false, false}); jshell> NDArrays.logicalOr(array1, array2); ND: (2) cpu() boolean [ true, false]
jshell> NDArray array = manager.arange(5f); jshell> NDArrays.logicalOr(array.lt(1), array.gt(3)); ND: (5) cpu() boolean [ true, false, false, false, true]
-
logicalXor
Computes the truth value ofNDArray
a ANDNDArray
b element-wise.Examples
jshell> NDArray array = manager.create(new boolean[] {true}); jshell> NDArrays.logicalXor(array1, array2); ND: (1) cpu() boolean [ true] jshell> array1 = manager.create(new boolean[] {true, false}); jshell> array2 = manager.create(new boolean[] {false, false}); jshell> NDArrays.logicalXor(array1, array2); ND: (2) cpu() boolean [ true, false]
jshell> NDArray array = manager.arange(5f); jshell> NDArrays.logicalXor(array.lt(1), array.gt(3)); ND: (5) cpu() boolean [ true, false, false, false, true]
-
erfinv
Returns element-wise inverse gauss error function of the inputNDArray
.Examples
jshell> NDArray array = manager.create(new float[] {0f, 0.5f, -1f}); jshell> NDArrays.erfinv(array); ND: (3) cpu() float32 [0., 0.4769, -inf]
- Parameters:
input
- The inputNDArray
- Returns:
- The inverse of gauss error of the input, element-wise
-
erf
Returns element-wise gauss error function of theNDArray
.Examples
jshell> NDArray array = manager.create(new float[] {0f, 0.4769f, Float.NEGATIVE_INFINITY}); jshell> array.erf(); ND: (3) cpu() float32 [0., 0.5, -1]
- Parameters:
input
- The inputNDArray
- Returns:
- The gauss error of the
NDArray
, element-wise
-