Class NDArrays
-
Method Summary
Modifier and TypeMethodDescriptionstatic NDArraystatic NDArrayAdds a number to theNDArrayelement-wise.static NDArrayAdds aNDArrayto a number element-wise.static NDArrayAdds all of theNDArrays together element-wise in place.static NDArrayAdds a number to theNDArrayelement-wise in place.static NDArrayAdds aNDArrayto a number element-wise in place.static booleanReturnstrueif twoNDArrayare element-wise equal within a tolerance.static booleanReturnstrueif twoNDArrayare element-wise equal within a tolerance.static NDArraybooleanMask(NDArray data, NDArray index) static NDArraybooleanMask(NDArray data, NDArray index, int axis) static NDArrayJoins aNDListalong the first axis.static NDArrayJoins aNDListalong an existing axis.static booleancontentEquals(NDArray a, NDArray b) static booleancontentEquals(NDArray a, Number n) static NDArraystatic NDArrayDivides theNDArrayby a number element-wise.static NDArrayDivides a number by aNDArrayelement-wise.static NDArraystatic NDArrayDivides a number by aNDArrayelement-wise in place.static NDArrayDivides a number by aNDArrayelement-wise.static NDArraystatic NDArrayReturns the booleanNDArrayfor element-wise "Equals" comparison.static NDArrayReturns the booleanNDArrayfor element-wise "Equals" comparison.static NDArrayReturns the booleanNDArrayfor element-wise "Equals" comparison.static NDArrayReturns element-wise gauss error function of theNDArray.static NDArrayReturns element-wise inverse gauss error function of the inputNDArray.static NDArrayReturns the booleanNDArrayfor element-wise "Greater Than" comparison.static NDArrayReturns the booleanNDArrayfor element-wise "Greater Than" comparison.static NDArrayReturns the booleanNDArrayfor element-wise "Greater Than" comparison.static NDArrayReturns the booleanNDArrayfor element-wise "Greater or equals" comparison.static NDArrayReturns the booleanNDArrayfor element-wise "Greater or equals" comparison.static NDArrayReturns the booleanNDArrayfor element-wise "Greater or equals" comparison.static NDArraylogicalAnd(NDArray a, NDArray b) static NDArraystatic NDArraylogicalXor(NDArray a, NDArray b) static NDArrayReturns the booleanNDArrayfor element-wise "Less" comparison.static NDArrayReturns the booleanNDArrayfor element-wise "Less" comparison.static NDArrayReturns the booleanNDArrayfor element-wise "Less" comparison.static NDArrayReturns the booleanNDArrayfor element-wise "Less or equals" comparison.static NDArrayReturns the booleanNDArrayfor element-wise "Less or equals" comparison.static NDArrayReturns the booleanNDArrayfor element-wise "Less or equals" comparison.static NDArrayProduct matrix of thisNDArrayand the otherNDArray.static NDArraystatic NDArrayReturns the maximum of aNDArrayand a number element-wise.static NDArrayReturns the maximum of a number and aNDArrayelement-wise.static NDArraystatic NDArrayReturns the minimum of aNDArrayand a number element-wise.static NDArrayReturns the minimum of a number and aNDArrayelement-wise.static NDArrayReturns element-wise remainder of division.static NDArrayReturns element-wise remainder of division.static NDArrayReturns element-wise remainder of division.static NDArrayReturns element-wise remainder of division.static NDArrayReturns element-wise remainder of division in place.static NDArrayReturns element-wise remainder of division in place.static NDArrayMultiplies all of theNDArrays together element-wise.static NDArrayMultiplies theNDArrayby a number element-wise.static NDArrayMultiplies a number by aNDArrayelement-wise.static NDArrayMultiplies all of theNDArrays together element-wise in place.static NDArrayMultiplies theNDArrayby a number element-wise in place.static NDArrayMultiplies a number by aNDArrayelement-wise.static NDArrayReturns the booleanNDArrayfor element-wise "Not equals" comparison.static NDArrayReturns the booleanNDArrayfor element-wise "Not equals" comparison.static NDArrayReturns the booleanNDArrayfor element-wise "Not equals" comparison.static NDArraystatic NDArrayTakes the power of theNDArraywith a number element-wise.static NDArrayTakes the power of a number with aNDArrayelement-wise.static NDArraystatic NDArrayTakes the power of theNDArraywith a number element-wise in place.static NDArrayTakes the power of a number with aNDArrayelement-wise in place.static NDArraysequenceMask(NDArray data, NDArray sequenceLength) static NDArraysequenceMask(NDArray data, NDArray sequenceLength, float value) static booleanshapeEquals(NDArray a, NDArray b) Checks 2NDArrays for equal shapes.static NDArraystatic NDArraystatic NDArraystatic NDArraySubtracts a number from theNDArrayelement-wise.static NDArraySubtracts aNDArrayfrom a number element-wise.static NDArraystatic NDArraySubtracts a number from theNDArrayelement-wise in place.static NDArraySubtracts aNDArrayfrom a number element-wise in place.static NDArray
-
Method Details
-
contentEquals
Returnstrueif all elements inNDArraya are equal toNDArrayb.Examples
jshell> NDArray array = manager.ones(new Shape(3)); jshell> NDArrays.contentEquals(array, 1); // return true instead of boolean NDArray true
- Parameters:
a- theNDArrayto comparen- the number to compare- Returns:
- the boolean result
-
contentEquals
Returnstrueif all elements inNDArraya are equal toNDArrayb.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 2NDArrays 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
Returnstrueif twoNDArrayare 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
Returnstrueif twoNDArrayare 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- theNDArrayto compare withb- theNDArrayto compare withrtol- the relative tolerance parameteratol- the absolute tolerance parameterequalNan- whether to compare NaN’s as equal. Iftrue, NaN’s in theNDArraywill be considered equal to NaN’s in the otherNDArray- Returns:
- the boolean result
-
eq
Returns the booleanNDArrayfor 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 booleanNDArrayfor 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 booleanNDArrayfor 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 booleanNDArrayfor 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 booleanNDArrayfor 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 booleanNDArrayfor 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 booleanNDArrayfor 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 booleanNDArrayfor 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
NDArrayfor element-wise "Greater Than" comparison
-
gt
Returns the booleanNDArrayfor 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 booleanNDArrayfor 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 booleanNDArrayfor 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 booleanNDArrayfor 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 booleanNDArrayfor 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 booleanNDArrayfor 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 booleanNDArrayfor 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 booleanNDArrayfor 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 booleanNDArrayfor 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 booleanNDArrayfor 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 theNDArrayor the otherNDArraydepending on condition.Given three
NDArrays, condition, a, and b, returns anNDArraywith the elements from a or b, depending on whether the elements from conditionNDArrayaretrueorfalse. If condition has the same shape as a, each element in the outputNDArrayis from this if the corresponding element in the condition istrue, and from other iffalse.Note that all non-zero values are interpreted as
truein 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 aNDArrayand 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 aNDArrayelement-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 ofNDArraya andNDArrayb element-wise.The shapes of
NDArraya andNDArrayb 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 aNDArrayand 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 aNDArrayelement-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 ofNDArraya andNDArrayb element-wise.The shapes of
NDArraya andNDArrayb 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 theNDArraygiven the index booleanNDArrayalong 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 givenNDArrayoutside the sequenceNDArrayto 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
sequenceLengthis used to handle variable-length sequences.sequenceLengthshould be an input array of positive ints of dimension [batch_size]. -
sequenceMask
Sets all elements of the givenNDArrayoutside the sequenceNDArrayto 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
sequenceLengthis used to handle variable-length sequences.sequenceLengthshould be an input array of positive ints of dimension [batch_size]. -
add
Adds a number to theNDArrayelement-wise.Examples
jshell> NDArray array = manager.create(new float[] {1f, 2f}); jshell> NDArrays.add(array, 2f); ND: (2) cpu() float32 [3., 4.] -
add
Adds aNDArrayto 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 aNDArrayto aNDArrayelement-wise.The shapes of all of the
NDArrays 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- theNDArrays 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 theNDArrayelement-wise.Examples
jshell> NDArray array = manager.create(new float[] {1f, 2f}); jshell> array.sub(2f); ND: (2) cpu() float32 [-1., 0.] -
sub
Subtracts aNDArrayfrom 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 aNDArrayfrom aNDArrayelement-wise.The shapes of
NDArraya andNDArrayb 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 theNDArrayby 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 aNDArrayelement-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 theNDArrays together element-wise.The shapes of all of the
NDArrays 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- theNDArrays 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 theNDArrayby 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 aNDArrayelement-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 aNDArrayby aNDArrayelement-wise.The shapes of
NDArraya andNDArrayb 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 theNDArraywith 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 aNDArrayelement-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 aNDArraywith aNDArrayelement-wise.The shapes of
NDArraya andNDArrayb 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 theNDArrayelement-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 aNDArrayto 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 theNDArrays together element-wise in place.The shapes of all of the
NDArrays 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- theNDArrays to add together- Returns:
- the result
NDArray - Throws:
IllegalArgumentException- arrays must have at least two elements
-
subi
Subtracts a number from theNDArrayelement-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 aNDArrayfrom 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 aNDArrayfrom aNDArrayelement-wise in place.The shapes of
NDArraya andNDArrayb 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 theNDArrayby 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 aNDArrayelement-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 theNDArrays together element-wise in place.The shapes of all of the
NDArrays 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- theNDArrays to multiply together- Returns:
- the result
NDArray - Throws:
IllegalArgumentException- arrays must have at least two elements
-
divi
Divides a number by aNDArrayelement-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 aNDArrayelement-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 aNDArrayby aNDArrayelement-wise.The shapes of
NDArraya andNDArrayb 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 theNDArraywith 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 aNDArrayelement-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 aNDArraywith aNDArrayelement-wise.The shapes of
NDArraya andNDArrayb 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 ofNDArraya andNDArrayb.- If both the
NDArrayand the otherNDArrayare 1-DNDArrays, it is inner product of vectors (without complex conjugation). - If both the
NDArrayand the otherNDArrayare 2-DNDArrays, it is matrix multiplication. - If either the
NDArrayor the otherNDArrayis 0-DNDArray(scalar), it is equivalent to mul. - If the
NDArrayis N-DNDArrayand the otherNDArrayis 1-DNDArray, it is a sum product over the last axis of those. - If the
NDArrayis N-DNDArrayand the otherNDArrayis M-DNDArray(where M>=2), it is a sum product over the last axis of thisNDArrayand 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 thisNDArrayand the otherNDArray.The behavior depends on the arguments in the following way.
- If both this
NDArrayand the otherNDArrayare 2-DNDArrays, they are multiplied like conventional matrices - If either this
NDArrayor the otherNDArrayis N-DNDArray, N > 2 , it is treated as a stack of matrices residing in the last two indexes and broadcast accordingly. - If this
NDArrayis 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
NDArrayis 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 ofNDArrays inNDListalong 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 ofNDArrays inNDListalong 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 aNDListalong 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 aNDListalong 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 ofNDArraya ANDNDArrayb element-wise.The shapes of
NDArraya andNDArrayb 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 ofNDArraya ANDNDArrayb 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 ofNDArraya ANDNDArrayb 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
-