Class NDArrays


  • public final class NDArrays
    extends java.lang.Object
    This class contains various methods for manipulating NDArrays.
    • Method Detail

      • contentEquals

        public static boolean contentEquals​(NDArray a,
                                            java.lang.Number n)
        Returns true if all elements in NDArray a are equal to NDArray b.

        Examples

         jshell> NDArray array = manager.ones(new Shape(3));
         jshell> NDArrays.contentEquals(array, 1); // return true instead of boolean NDArray
         true
         
        Parameters:
        a - the NDArray to compare
        n - the number to compare
        Returns:
        the boolean result
      • contentEquals

        public static boolean contentEquals​(NDArray a,
                                            NDArray b)
        Returns true if all elements in NDArray a are equal to NDArray 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
         
        Parameters:
        a - the NDArray to compare
        b - the NDArray to compare
        Returns:
        the boolean result
      • shapeEquals

        public static boolean shapeEquals​(NDArray a,
                                          NDArray b)
        Checks 2 NDArrays for equal shapes.

        Shapes are considered equal if:

        • Both NDArrays have equal rank, and
        • size(0)...size(rank()-1) are equal for both NDArrays

        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
         
        Parameters:
        a - the NDArray to compare
        b - the NDArray to compare
        Returns:
        true if the Shapes are the same
      • allClose

        public static boolean allClose​(NDArray a,
                                       NDArray b)
        Returns true if two NDArray 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
         
        Parameters:
        a - the NDArray to compare with
        b - the NDArray to compare with
        Returns:
        the boolean result
      • allClose

        public static boolean allClose​(NDArray a,
                                       NDArray b,
                                       double rtol,
                                       double atol,
                                       boolean equalNan)
        Returns true if two NDArray 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 - the NDArray to compare with
        b - the NDArray to compare with
        rtol - the relative tolerance parameter
        atol - the absolute tolerance parameter
        equalNan - whether to compare NaN’s as equal. If true, NaN’s in the NDArray will be considered equal to NaN’s in the other NDArray
        Returns:
        the boolean result
      • eq

        public static NDArray eq​(NDArray a,
                                 java.lang.Number n)
        Returns the boolean NDArray for element-wise "Equals" comparison.

        Examples

         jshell> NDArray array = manager.ones(new Shape(1));
         jshell> NDArrays.eq(array, 1);
         ND: (1) cpu() boolean
         [ true]
         
        Parameters:
        a - the NDArray to compare
        n - the number to compare
        Returns:
        the boolean NDArray for element-wise "Equals" comparison
      • eq

        public static NDArray eq​(java.lang.Number n,
                                 NDArray a)
        Returns the boolean NDArray for element-wise "Equals" comparison.

        Examples

         jshell> NDArray array = manager.ones(new Shape(1));
         jshell> NDArrays.eq(1, array);
         ND: (1) cpu() boolean
         [ true]
         
        Parameters:
        n - the number to compare
        a - the NDArray to compare
        Returns:
        the boolean NDArray for element-wise "Equals" comparison
      • eq

        public static NDArray eq​(NDArray a,
                                 NDArray b)
        Returns the boolean NDArray 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]
         
        Parameters:
        a - the NDArray to compare
        b - the NDArray to compare
        Returns:
        the boolean NDArray for element-wise "Equals" comparison
      • neq

        public static NDArray neq​(NDArray a,
                                  java.lang.Number n)
        Returns the boolean NDArray 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],
         ]
         
        Parameters:
        a - the NDArray to compare
        n - the number to compare
        Returns:
        the boolean NDArray for element-wise "Not equals" comparison
      • neq

        public static NDArray neq​(java.lang.Number n,
                                  NDArray a)
        Returns the boolean NDArray 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],
         ]
         
        Parameters:
        n - the number to compare
        a - the NDArray to compare
        Returns:
        the boolean NDArray for element-wise "Not equals" comparison
      • neq

        public static NDArray neq​(NDArray a,
                                  NDArray b)
        Returns the boolean 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> 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],
         ]
         
        Parameters:
        a - the NDArray to compare
        b - the NDArray to compare
        Returns:
        the boolean NDArray for element-wise "Not equals" comparison
      • gt

        public static NDArray gt​(NDArray a,
                                 java.lang.Number n)
        Returns the boolean NDArray 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]
         
        Parameters:
        a - the NDArray to compare
        n - the number to be compared against
        Returns:
        the boolean NDArray for element-wise "Greater Than" comparison
      • gt

        public static NDArray gt​(java.lang.Number n,
                                 NDArray a)
        Returns the boolean NDArray 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 compared
        a - the NDArray to be compared against
        Returns:
        the boolean NDArray for element-wise "Greater Than" comparison
      • gt

        public static NDArray gt​(NDArray a,
                                 NDArray b)
        Returns the boolean 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> NDArrays.gt(array1, array2);
         ND: (2) cpu() boolean
         [ true, false]
         
        Parameters:
        a - the NDArray to be compared
        b - the NDArray to be compared against
        Returns:
        the boolean NDArray for element-wise "Greater Than" comparison
      • gte

        public static NDArray gte​(NDArray a,
                                  java.lang.Number n)
        Returns the boolean NDArray 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]
         
        Parameters:
        a - the NDArray to be compared
        n - the number to be compared against
        Returns:
        the boolean NDArray for element-wise "Greater or equals" comparison
      • gte

        public static NDArray gte​(java.lang.Number n,
                                  NDArray a)
        Returns the boolean NDArray 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]
         
        Parameters:
        n - the number to be compared
        a - the NDArray to be compared against
        Returns:
        the boolean NDArray for element-wise "Greater or equals" comparison
      • gte

        public static NDArray gte​(NDArray a,
                                  NDArray b)
        Returns the boolean 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> NDArrays.gte(array1, array2);
         ND: (2) cpu() boolean
         [ true, true]
         
        Parameters:
        a - the NDArray to be compared
        b - the NDArray to be compared against
        Returns:
        the boolean NDArray for element-wise "Greater or equals" comparison
      • lt

        public static NDArray lt​(NDArray a,
                                 java.lang.Number n)
        Returns the boolean NDArray 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]
         
        Parameters:
        a - the NDArray to be compared
        n - the number to be compared against
        Returns:
        the boolean NDArray for element-wise "Less" comparison
      • lt

        public static NDArray lt​(java.lang.Number n,
                                 NDArray a)
        Returns the boolean NDArray 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]
         
        Parameters:
        n - the number to be compared
        a - the NDArray to be compared against
        Returns:
        the boolean NDArray for element-wise "Less" comparison
      • lt

        public static NDArray lt​(NDArray a,
                                 NDArray b)
        Returns the boolean 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> NDArrays.lt(array1, array2);
         ND: (2) cpu() boolean
         [ true, false]
         
        Parameters:
        a - the NDArray to be compared
        b - the NDArray to be compared against
        Returns:
        the boolean NDArray for element-wise "Less" comparison
      • lte

        public static NDArray lte​(NDArray a,
                                  java.lang.Number n)
        Returns the boolean NDArray 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]
         
        Parameters:
        a - the NDArray to be compared
        n - the number to be compared against
        Returns:
        the boolean NDArray for element-wise "Less or equals" comparison
      • lte

        public static NDArray lte​(java.lang.Number n,
                                  NDArray a)
        Returns the boolean NDArray 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]
         
        Parameters:
        n - the number to be compared
        a - the NDArray to be compared against
        Returns:
        the boolean NDArray for element-wise "Less or equals" comparison
      • lte

        public static NDArray lte​(NDArray a,
                                  NDArray b)
        Returns the boolean 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> NDArrays.lte(array1, array2)
         ND: (2) cpu() boolean
         [ true, true]
         
        Parameters:
        a - the NDArray to be compared
        b - the NDArray to be compared against
        Returns:
        the boolean NDArray for element-wise "Less or equals" comparison
      • where

        public static NDArray where​(NDArray condition,
                                    NDArray a,
                                    NDArray b)
        Returns elements chosen from the NDArray or the other NDArray depending on condition.

        Given three NDArrays, condition, a, and b, returns an NDArray with the elements from a or b, depending on whether the elements from condition NDArray are true or false. If condition has the same shape as a, each element in the output NDArray is from this if the corresponding element in the condition is true, and from other if false.

        Note that all non-zero values are interpreted as true in condition NDArray.

        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.],
         ]
         
        Parameters:
        condition - the condition NDArray
        a - the first NDArray
        b - the other NDArray
        Returns:
        the result NDArray
      • maximum

        public static NDArray maximum​(NDArray a,
                                      java.lang.Number n)
        Returns the maximum of a NDArray 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.]
         
        Parameters:
        a - the NDArray to be compared
        n - the number to be compared
        Returns:
        the maximum of a NDArray and a number element-wise
      • maximum

        public static NDArray maximum​(java.lang.Number n,
                                      NDArray a)
        Returns the maximum of a number and a NDArray 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.]
         
        Parameters:
        n - the number to be compared
        a - the NDArray to be compared
        Returns:
        the maximum of a number and a NDArray element-wise
      • maximum

        public static NDArray maximum​(NDArray a,
                                      NDArray b)
        Returns the maximum of NDArray a and NDArray b element-wise.

        The shapes of NDArray a and NDArray 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. ],
         ]
         
        Parameters:
        a - the NDArray to be compared
        b - the NDArray to be compared
        Returns:
        the maximum of NDArray a and NDArray b element-wise
      • minimum

        public static NDArray minimum​(NDArray a,
                                      java.lang.Number n)
        Returns the minimum of a NDArray 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.]
         
        Parameters:
        a - the NDArray to be compared
        n - the number to be compared
        Returns:
        the minimum of a NDArray and a number element-wise
      • minimum

        public static NDArray minimum​(java.lang.Number n,
                                      NDArray a)
        Returns the minimum of a number and a NDArray 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.]
         
        Parameters:
        n - the number to be compared
        a - the NDArray to be compared
        Returns:
        the minimum of a number and a NDArray element-wise
      • minimum

        public static NDArray minimum​(NDArray a,
                                      NDArray b)
        Returns the minimum of NDArray a and NDArray b element-wise.

        The shapes of NDArray a and NDArray 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. ],
         ]
         
        Parameters:
        a - the NDArray to be compared
        b - the NDArray to be compared
        Returns:
        the minimum of NDArray a and NDArray b element-wise
      • booleanMask

        public static NDArray booleanMask​(NDArray data,
                                          NDArray index)
        Returns portion of the NDArray given the index boolean NDArray 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.],
         ]
         
        Parameters:
        data - the NDArray to operate on
        index - the boolean NDArray mask
        Returns:
        the result NDArray
      • booleanMask

        public static NDArray booleanMask​(NDArray data,
                                          NDArray index,
                                          int axis)
        Returns portion of the NDArray given the index boolean NDArray along given axis.
        Parameters:
        data - the NDArray to operate on
        index - the boolean NDArray mask
        axis - an integer that represents the axis of NDArray to mask from
        Returns:
        the result NDArray
      • sequenceMask

        public static NDArray sequenceMask​(NDArray data,
                                           NDArray sequenceLength,
                                           float value)
        Sets all elements of the given NDArray outside the sequence NDArray 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].

        Parameters:
        data - the NDArray to operate on
        sequenceLength - used to handle variable-length sequences
        value - the constant value to be set
        Returns:
        the result NDArray
      • sequenceMask

        public static NDArray sequenceMask​(NDArray data,
                                           NDArray sequenceLength)
        Sets all elements of the given NDArray outside the sequence NDArray 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].

        Parameters:
        data - the NDArray to operate on
        sequenceLength - used to handle variable-length sequences
        Returns:
        the result NDArray
      • add

        public static NDArray add​(NDArray a,
                                  java.lang.Number n)
        Adds a number to the NDArray element-wise.

        Examples

         jshell> NDArray array = manager.create(new float[] {1f, 2f});
         jshell> NDArrays.add(array, 2f);
         ND: (2) cpu() float32
         [3., 4.]
         
        Parameters:
        a - the NDArray to be added to
        n - the number to add
        Returns:
        the result NDArray
      • add

        public static NDArray add​(java.lang.Number n,
                                  NDArray a)
        Adds a NDArray 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.]
         
        Parameters:
        n - the number to be added to
        a - the NDArray to add
        Returns:
        the result NDArray
      • add

        public static NDArray add​(NDArray... arrays)
        Adds a NDArray to a NDArray 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.add(array, array, array);
         ND: (2) cpu() float32
         [3., 6.]
         
        Parameters:
        arrays - the NDArrays to add together
        Returns:
        the result NDArray
        Throws:
        java.lang.IllegalArgumentException - arrays must have at least two elements
        java.lang.IllegalArgumentException - the shape of all inputs must be the same
      • sub

        public static NDArray sub​(NDArray a,
                                  java.lang.Number n)
        Subtracts a number from the NDArray element-wise.

        Examples

         jshell> NDArray array = manager.create(new float[] {1f, 2f});
         jshell> array.sub(2f);
         ND: (2) cpu() float32
         [-1.,  0.]
         
        Parameters:
        a - the NDArray to be subtracted
        n - the number to subtract from
        Returns:
        the result NDArray
      • sub

        public static NDArray sub​(java.lang.Number n,
                                  NDArray a)
        Subtracts a NDArray 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.]
         
        Parameters:
        n - the number to be subtracted
        a - the NDArray to subtract from
        Returns:
        the result NDArray
      • sub

        public static NDArray sub​(NDArray a,
                                  NDArray b)
        Subtracts a NDArray from a NDArray element-wise.

        The shapes of NDArray a and NDArray 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.],
         ]
         
        Parameters:
        a - the NDArray to be subtracted
        b - the NDArray to subtract from
        Returns:
        the result NDArray
      • mul

        public static NDArray mul​(NDArray a,
                                  java.lang.Number n)
        Multiplies the NDArray 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 multiplied
        n - the number to multiply by
        Returns:
        the result NDArray
      • mul

        public static NDArray mul​(java.lang.Number n,
                                  NDArray a)
        Multiplies a number by a NDArray element-wise.

        Examples

         jshell> NDArray array = manager.create(new float[] {1f, 2f});
         jshell> NDArrays.mul(3f, array);
         ND: (2) cpu() float32
         [3., 6.]
         
        Parameters:
        n - the number to be multiplied
        a - the NDArray to multiply by
        Returns:
        the result NDArray
      • mul

        public static NDArray mul​(NDArray... arrays)
        Multiplies all of the NDArrays 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 - the NDArrays to multiply together
        Returns:
        the result NDArray
        Throws:
        java.lang.IllegalArgumentException - arrays must have at least two elements
        java.lang.IllegalArgumentException - the shape of all inputs must be the same
      • div

        public static NDArray div​(NDArray a,
                                  java.lang.Number n)
        Divides the NDArray 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.  ]
         
        Parameters:
        a - the NDArray to be be divided
        n - the number to divide by
        Returns:
        the result NDArray
      • div

        public static NDArray div​(java.lang.Number n,
                                  NDArray a)
        Divides a number by a NDArray 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   ]
         
        Parameters:
        n - the number to be be divided
        a - the NDArray to divide by
        Returns:
        the result NDArray
      • div

        public static NDArray div​(NDArray a,
                                  NDArray b)
        Divides a NDArray by a NDArray element-wise.

        The shapes of NDArray a and NDArray 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],
         ]
         
        Parameters:
        a - the NDArray to be be divided
        b - the NDArray to divide by
        Returns:
        the result NDArray
      • mod

        public static NDArray mod​(NDArray a,
                                  java.lang.Number n)
        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.]
         
        Parameters:
        a - the dividend NDArray
        n - the divisor number
        Returns:
        the result NDArray
      • mod

        public static NDArray mod​(java.lang.Number n,
                                  NDArray a)
        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.]
         
        Parameters:
        n - the dividend number
        a - the divisor NDArray
        Returns:
        the result NDArray
      • mod

        public static NDArray mod​(NDArray a,
                                  NDArray b)
        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 NDArray
        b - the dividend NDArray
        Returns:
        the result NDArray
      • pow

        public static NDArray pow​(NDArray a,
                                  java.lang.Number n)
        Takes the power of the NDArray 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.]
         
        Parameters:
        a - the NDArray to be taken the power with
        n - the number to take the power with
        Returns:
        the result NDArray
      • pow

        public static NDArray pow​(java.lang.Number n,
                                  NDArray a)
        Takes the power of a number with a NDArray element-wise.

        Examples

         jshell> NDArray array = manager.arange(5f);
         jshell> NDArrays.pow(4f, array);
         ND: (5) cpu() float32
         [  1.,   4.,  16.,  64., 256.]
         
        Parameters:
        n - the number to be taken the power with
        a - the NDArray to take the power with
        Returns:
        the result NDArray
      • pow

        public static NDArray pow​(NDArray a,
                                  NDArray b)
        Takes the power of a NDArray with a NDArray element-wise.

        The shapes of NDArray a and NDArray 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.],
         ]
         
        Parameters:
        a - the NDArray to be taken the power with
        b - the NDArray to take the power with
        Returns:
        the result NDArray
      • addi

        public static NDArray addi​(NDArray a,
                                   java.lang.Number n)
        Adds a number to the NDArray 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.]
         
        Parameters:
        a - the NDArray to be added to
        n - the number to add
        Returns:
        the result NDArray
      • addi

        public static NDArray addi​(java.lang.Number n,
                                   NDArray a)
        Adds a NDArray 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.]
         
        Parameters:
        a - the number to be added to
        n - the NDArray to add
        Returns:
        the result NDArray
      • addi

        public static NDArray addi​(NDArray... arrays)
        Adds all of the NDArrays 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 - the NDArrays to add together
        Returns:
        the result NDArray
        Throws:
        java.lang.IllegalArgumentException - arrays must have at least two elements
      • subi

        public static NDArray subi​(NDArray a,
                                   java.lang.Number n)
        Subtracts a number from the NDArray 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.]
         
        Parameters:
        a - the NDArray to be subtracted
        n - the number to subtract from
        Returns:
        the result NDArray
      • subi

        public static NDArray subi​(java.lang.Number n,
                                   NDArray a)
        Subtracts a NDArray 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.]
         
        Parameters:
        n - the number to be subtracted
        a - the NDArray to subtract from
        Returns:
        the result NDArray
      • subi

        public static NDArray subi​(NDArray a,
                                   NDArray b)
        Subtracts a NDArray from a NDArray element-wise in place.

        The shapes of NDArray a and NDArray 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.],
         ]
         
        Parameters:
        a - the NDArray to be subtracted
        b - the NDArray to subtract from
        Returns:
        the result NDArray
      • muli

        public static NDArray muli​(NDArray a,
                                   java.lang.Number n)
        Multiplies the NDArray 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 multiplied
        n - the number to multiply by
        Returns:
        the result NDArray
      • muli

        public static NDArray muli​(java.lang.Number n,
                                   NDArray a)
        Multiplies a number by a NDArray 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.]
         
        Parameters:
        n - the number to multiply by
        a - the NDArray to multiply by
        Returns:
        the result NDArray
      • muli

        public static NDArray muli​(NDArray... arrays)
        Multiplies all of the NDArrays 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 - the NDArrays to multiply together
        Returns:
        the result NDArray
        Throws:
        java.lang.IllegalArgumentException - arrays must have at least two elements
      • divi

        public static NDArray divi​(NDArray a,
                                   java.lang.Number n)
        Divides a number by a NDArray 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.  ]
         
        Parameters:
        a - the NDArray to be be divided
        n - the number to divide by
        Returns:
        the result NDArray
      • divi

        public static NDArray divi​(java.lang.Number n,
                                   NDArray a)
        Divides a number by a NDArray 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   ]
         
        Parameters:
        n - the number to be be divided
        a - the NDArray to divide by
        Returns:
        the result NDArray
      • divi

        public static NDArray divi​(NDArray a,
                                   NDArray b)
        Divides a NDArray by a NDArray element-wise.

        The shapes of NDArray a and NDArray 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],
         ]
         
        Parameters:
        a - the NDArray to be be divided
        b - the NDArray to divide by
        Returns:
        the result NDArray
      • modi

        public static NDArray modi​(NDArray a,
                                   java.lang.Number n)
        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.]
         
        Parameters:
        a - the dividend NDArray
        n - the divisor number
        Returns:
        the result NDArray
      • modi

        public static NDArray modi​(java.lang.Number n,
                                   NDArray a)
        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.]
         
        Parameters:
        n - the dividend number
        a - the divisor NDArray
        Returns:
        the result NDArray
      • modi

        public static NDArray modi​(NDArray a,
                                   NDArray b)
        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 NDArray
        b - the dividend NDArray
        Returns:
        the result NDArray
      • powi

        public static NDArray powi​(NDArray a,
                                   java.lang.Number n)
        Takes the power of the NDArray 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.]
         
        Parameters:
        a - the NDArray to be taken the power with
        n - the number to take the power with
        Returns:
        the result NDArray
      • powi

        public static NDArray powi​(java.lang.Number n,
                                   NDArray a)
        Takes the power of a number with a NDArray 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.]
         
        Parameters:
        n - the number to be taken the power with
        a - the NDArray to take the power with
        Returns:
        the result NDArray
      • powi

        public static NDArray powi​(NDArray a,
                                   NDArray b)
        Takes the power of a NDArray with a NDArray element-wise.

        The shapes of NDArray a and NDArray 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.],
         ]
         
        Parameters:
        a - the NDArray to be taken the power with
        b - the NDArray to take the power with
        Returns:
        the result NDArray
      • dot

        public static NDArray dot​(NDArray a,
                                  NDArray b)
        Dot product of NDArray a and NDArray b.

        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.],
          ],
         ]
         
        Parameters:
        a - the NDArray to perform dot product with
        b - the NDArray to perform dot product with
        Returns:
        the result NDArray
      • matMul

        public static NDArray matMul​(NDArray a,
                                     NDArray b)
        Product matrix of this NDArray and the other NDArray.

        The behavior depends on the arguments in the following way.

        • If both this NDArray and the other NDArray are 2-D NDArrays, they are multiplied like conventional matrices
        • If either this 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.
        • If this 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.
        • If other 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> 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.
         
        Parameters:
        a - the NDArray to perform matrix product with
        b - the NDArray to perform matrix product with
        Returns:
        the result NDArray
      • stack

        public static NDArray stack​(NDList arrays)
        Joins a sequence of NDArrays in NDList 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.],
         ]
         
        Parameters:
        arrays - the input NDList. Each NDArray in the NDList must have the same shape as the NDArray
        Returns:
        the result NDArray. The stacked NDArray has one more dimension than the NDArrays in NDList
      • stack

        public static NDArray stack​(NDList arrays,
                                    int axis)
        Joins a sequence of NDArrays in NDList 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.],
         ]
         
        Parameters:
        arrays - the input NDList. Each NDArray in the NDList must have the same shape as the NDArray
        axis - the axis in the result NDArray along which the input NDList are stacked
        Returns:
        the result NDArray. The stacked NDArray has one more dimension than the the NDArray
      • concat

        public static NDArray concat​(NDList arrays)
        Joins a NDList 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.]
         
        Parameters:
        arrays - a NDList which have the same shape as the NDArray, except in the dimension corresponding to axis
        Returns:
        the concatenated NDArray
      • concat

        public static NDArray concat​(NDList arrays,
                                     int axis)
        Joins a NDList 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.],
         ]
         
        Parameters:
        arrays - a NDList which have the same shape as the NDArray, except in the dimension corresponding to axis
        axis - the axis along which the NDList will be joined
        Returns:
        the concatenated NDArray
      • logicalAnd

        public static NDArray logicalAnd​(NDArray a,
                                         NDArray b)
        Returns the truth value of NDArray a AND NDArray b element-wise.

        The shapes of NDArray a and NDArray 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]
         
        Parameters:
        a - the NDArray to operate on
        b - the NDArray to operate on
        Returns:
        the boolean NDArray of the logical AND operation applied to the elements of the NDArray a and NDArray b
      • logicalOr

        public static NDArray logicalOr​(NDArray a,
                                        NDArray b)
        Computes the truth value of NDArray a AND NDArray 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]
         
        Parameters:
        a - the NDArray to operate on
        b - the NDArray to operate on
        Returns:
        the boolean NDArray of the logical AND operation applied to the elements of the NDArray a and NDArray b
      • logicalXor

        public static NDArray logicalXor​(NDArray a,
                                         NDArray b)
        Computes the truth value of NDArray a AND NDArray 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]
         
        Parameters:
        a - the NDArray to operate on
        b - the NDArray to operate on
        Returns:
        the boolean NDArray of the logical XOR operation applied to the elements of the NDArray a and NDArray b
      • erfinv

        public static NDArray erfinv​(NDArray input)
        Returns element-wise inverse gauss error function of the input NDArray.

        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 input NDArray
        Returns:
        The inverse of gauss error of the input, element-wise