Interface NDArray<T>

    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      T accumulate​(BinaryOperator<T> func)
      Returns the result of accumulation of all elements in this NDArray.
      NDArray<T> accumulate​(BinaryOperator<T> func, int... selectedDims)
      Returns the accumulation of all elements along the specified dimensions in this NDArray.
      default NDArray<T> add​(byte addend)
      Creates a new NDArray of the same shape and fills it with the values of this NDArray incremented by the given value.
      default NDArray<T> add​(double addend)
      Creates a new NDArray of the same shape and fills it with the values of this NDArray incremented by the given value.
      default NDArray<T> add​(float addend)
      Creates a new NDArray of the same shape and fills it with the values of this NDArray incremented by the given value.
      default NDArray<T> add​(int addend)
      Creates a new NDArray of the same shape and fills it with the values of this NDArray incremented by the given value.
      default NDArray<T> add​(long addend)
      Creates a new NDArray of the same shape and fills it with the values of this NDArray incremented by the given value.
      default NDArray<T> add​(short addend)
      Creates a new NDArray of the same shape and fills it with the values of this NDArray incremented by the given value.
      default NDArray<T> add​(NDArray<?> addend)
      Creates a new NDArray of the same shape and fills it with the element-wise sum of this NDArray and the NDArray given as parameter.
      NDArray<T> add​(Object... addends)
      Creates a new NDArray of the same shape and fills it with the element-wise sum of this NDArray and the parameter NDArrays and scalars.
      default NDArray<T> addInplace​(byte addend)
      Updates this NDArray by incrementing all entries with the given value.
      default NDArray<T> addInplace​(double addend)
      Updates this NDArray by incrementing all entries with the given value.
      default NDArray<T> addInplace​(float addend)
      Updates this NDArray by incrementing all entries with the given value.
      default NDArray<T> addInplace​(int addend)
      Updates this NDArray by incrementing all entries with the given value.
      default NDArray<T> addInplace​(long addend)
      Updates this NDArray by incrementing all entries with the given value.
      default NDArray<T> addInplace​(short addend)
      Updates this NDArray by incrementing all entries with the given value.
      default NDArray<T> addInplace​(NDArray<?> addend)
      Updates this NDArray with the element-wise sum of this NDArray and the one given as parameter.
      NDArray<T> addInplace​(Object... addends)
      Updates this NDArray with the element-wise sum of this NDArray and the ones given as parameters.
      NDArray<T> apply​(UnaryOperator<T> func)
      Apply the given function to each element of the array, and override each entry with the calculated new values.
      NDArray<T> applyOnSlices​(BiFunction<NDArray<T>,​int[],​NDArray<?>> func, int... iterationDims)
      Apply the given function to each slices of the array, and override each entry with the returned slice.
      NDArray<T> applyWithCartesianIndices​(BiFunction<T,​int[],​T> func)
      Apply the given function to each element of the array, and override each entry with the calculated new values.
      NDArray<T> applyWithLinearIndices​(BiFunction<T,​Integer,​T> func)
      Apply the given function to each element of the array, and override each entry with the calculated new values.
      NDArray<T> concatenate​(int axis, NDArray<?>... arrays)
      Creates a new NDArray that contains the elements of this NDArrays and all other NDArrays concatenated along the dimension/axis specified by the first parameter.
      boolean contains​(Object o)  
      String contentToString()
      Returns a String containing tabular representation of the array.
      String contentToString​(String format)
      Returns a String containing tabular representation of the array.
      NDArray<T> copy()
      Returns a copy of this NDArray.
      NDArray<T> copyFrom​(byte[] array)
      Updates this NDArray with the elements of the array given as parameter.
      NDArray<T> copyFrom​(double[] array)
      Updates this NDArray with the elements of the array given as parameter.
      NDArray<T> copyFrom​(float[] array)
      Updates this NDArray with the elements of the array given as parameter.
      NDArray<T> copyFrom​(int[] array)
      Updates this NDArray with the elements of the array given as parameter.
      NDArray<T> copyFrom​(long[] array)
      Updates this NDArray with the elements of the array given as parameter.
      NDArray<T> copyFrom​(short[] array)
      Updates this NDArray with the elements of the array given as parameter.
      NDArray<T> copyFrom​(NDArray<?> array)
      Updates this NDArray with the elements of the NDArray given as parameter.
      NDArray<T> copyFrom​(Object[] array)
      Updates this NDArray with the elements of the array given as parameter.
      String dataTypeAsString()
      Returns a String representation of element type.
      default NDArray<T> divide​(byte divisor)
      Creates a new NDArray of the same shape and fills it with the values of this NDArray divided by the given value.
      default NDArray<T> divide​(double divisor)
      Creates a new NDArray of the same shape and fills it with the values of this NDArray divided by the given value.
      default NDArray<T> divide​(float divisor)
      Creates a new NDArray of the same shape and fills it with the values of this NDArray divided by the given value.
      default NDArray<T> divide​(int divisor)
      Creates a new NDArray of the same shape and fills it with the values of this NDArray divided by the given value.
      default NDArray<T> divide​(long divisor)
      Creates a new NDArray of the same shape and fills it with the values of this NDArray divided by the given value.
      default NDArray<T> divide​(short divisor)
      Creates a new NDArray of the same shape and fills it with the values of this NDArray divided by the given value.
      default NDArray<T> divide​(NDArray<?> divisor)
      Creates a new NDArray of the same shape and fills it with the element-wise division of this NDArray and the NDArray given as parameter.
      NDArray<T> divide​(Object... divisors)
      Creates a new NDArray of the same shape and fills it with the result of the element-wise division of this NDArray by the parameter NDArrays and scalars.
      default NDArray<T> divideInplace​(byte divisor)
      Updates the elements this NDArray with the values of this NDArray divided by the given value.
      default NDArray<T> divideInplace​(double divisor)
      Updates the elements this NDArray with the values of this NDArray divided by the given value.
      default NDArray<T> divideInplace​(float divisor)
      Updates the elements this NDArray with the values of this NDArray divided by the given value.
      default NDArray<T> divideInplace​(int divisor)
      Updates the elements this NDArray with the values of this NDArray divided by the given value.
      default NDArray<T> divideInplace​(long divisor)
      Updates the elements this NDArray with the values of this NDArray divided by the given value.
      default NDArray<T> divideInplace​(short divisor)
      Updates the elements this NDArray with the values of this NDArray divided by the given value.
      default NDArray<T> divideInplace​(NDArray<?> divisor)
      Updates the elements this NDArray with the element-wise division of this NDArray and the NDArray given as parameter.
      NDArray<T> divideInplace​(Object... divisors)
      Updates the elements this NDArray with the result of the element-wise division of this NDArray by the parameter NDArrays and scalars.
      NDArray<T> dropDims​(int... droppedDims)
      Returns a view that references this NDArray as parent, and skips all singleton dimensions included in the parameter list.
      Class<?> dtype()
      Returns the type of values returned by get method.
      boolean equals​(Object obj)
      Compares the specified object with this NDArray for equality.
      NDArray<T> fill​(double value)
      Fill this NDArray with the specified value
      NDArray<T> fill​(T value)
      Fill this NDArray with the specified value
      NDArray<T> fillUsingCartesianIndices​(Function<int[],​T> func)
      Apply the given function to each element of the array, and override each entry with the calculated new values.
      NDArray<T> fillUsingLinearIndices​(IntFunction<T> func)
      Apply the given function to each element of the array, and override each entry with the calculated new values.
      void forEach​(Consumer<? super T> func)
      Apply the given function to each element of the array, and override each entry with the calculated new values.
      void forEachWithCartesianIndices​(BiConsumer<T,​int[]> func)
      Apply the given function to each element of the array, and override each entry with the calculated new values.
      void forEachWithLinearIndices​(ObjIntConsumer<T> func)
      Apply the given function to each element of the array, and override each entry with the calculated new values.
      T get​(int linearIndex)
      Returns an element specified by linear indexing.
      T get​(int... indices)
      Returns an element specified by cartesian indexing.
      String getNamePrefix()
      Returns a string that identifies the implementation behind this current object.
      int hashCode()
      This method is unsupported because NDArrays should not be used as keys in hash-based collections.
      NDArray<T> inverseMask​(NDArray<?> inverseMask)
      Returns an array view referencing this NDArray as parent that gives read-write access to a specific elements of the array selected by the given inverseMask.
      Iterator<T> iterator()
      Returns an iterator over the elements in this collection.
      int length()
      Returns the number of elements within this NDArray.
      NDArray<T> map​(UnaryOperator<T> func)
      Apply the given function to each element of the array, and create a new NDArray with the calculated new values.
      NDArray<T> mapOnSlices​(BiFunction<NDArray<T>,​int[],​NDArray<?>> func, int... iterationDims)
      Apply the given function to each slices of the array, and create a new NDArray with the calculated new values.
      NDArray<T> mapWithCartesianIndices​(BiFunction<T,​int[],​T> func)
      Apply the given function to each element of the array, and create a new NDArray with the calculated new values.
      NDArray<T> mapWithLinearIndices​(BiFunction<T,​Integer,​T> func)
      Apply the given function to each element of the array, and create a new NDArray with the calculated new values.
      NDArray<T> mask​(NDArray<?> mask)
      Returns an array view referencing this NDArray as parent that gives read-write access to a specific elements of the array selected by the given mask.
      NDArray<T> mask​(Predicate<T> func)
      Returns an array view referencing this NDArray as parent that gives read-write access to a specific elements for which the given function returns true.
      NDArray<T> maskWithCartesianIndices​(BiPredicate<T,​int[]> func)
      Returns an array view referencing this NDArray as parent that gives read-write access to a specific elements for which the given function returns true.
      NDArray<T> maskWithLinearIndices​(BiPredicate<T,​Integer> func)
      Returns an array view referencing this NDArray as parent that gives read-write access to a specific elements for which the given function returns true.
      default NDArray<T> multiply​(byte multiplicand)
      Creates a new NDArray of the same shape and fills it with the values of this NDArray multiplied by the given value.
      default NDArray<T> multiply​(double multiplicand)
      Creates a new NDArray of the same shape and fills it with the values of this NDArray multiplied by the given value.
      default NDArray<T> multiply​(float multiplicand)
      Creates a new NDArray of the same shape and fills it with the values of this NDArray multiplied by the given value.
      default NDArray<T> multiply​(int multiplicand)
      Creates a new NDArray of the same shape and fills it with the values of this NDArray multiplied by the given value.
      default NDArray<T> multiply​(long multiplicand)
      Creates a new NDArray of the same shape and fills it with the values of this NDArray multiplied by the given value.
      default NDArray<T> multiply​(short multiplicand)
      Creates a new NDArray of the same shape and fills it with the values of this NDArray multiplied by the given value.
      default NDArray<T> multiply​(NDArray<?> multiplicand)
      Creates a new NDArray of the same shape and fills it with the element-wise product of this NDArray and the NDArray given as parameter.
      NDArray<T> multiply​(Object... multiplicands)
      Creates a new NDArray of the same shape and fills it with the element-wise product of this NDArray and the parameter NDArrays and scalars.
      default NDArray<T> multiplyInplace​(byte multiplicand)
      Updates the elements of this NDArray with the values of this NDArray multiplied by the given value.
      default NDArray<T> multiplyInplace​(double multiplicand)
      Updates the elements of this NDArray with the values of this NDArray multiplied by the given value.
      default NDArray<T> multiplyInplace​(float multiplicand)
      Updates the elements of this NDArray with the values of this NDArray multiplied by the given value.
      default NDArray<T> multiplyInplace​(int multiplicand)
      Updates the elements of this NDArray with the values of this NDArray multiplied by the given value.
      default NDArray<T> multiplyInplace​(long multiplicand)
      Updates the elements of this NDArray with the values of this NDArray multiplied by the given value.
      default NDArray<T> multiplyInplace​(short multiplicand)
      Updates the elements of this NDArray with the values of this NDArray multiplied by the given value.
      default NDArray<T> multiplyInplace​(NDArray<?> multiplicand)
      Updates the elements of this NDArray with the element-wise product of this NDArray and the NDArray given as parameter.
      NDArray<T> multiplyInplace​(Object... multiplicands)
      Updates the elements of this NDArray with the element-wise product of this NDArray and the parameter NDArrays and scalars.
      int ndim()
      Returns the number of dimensions.
      double norm()
      Returns the 2-norm (Euclidean norm) of the vectorized array.
      default double norm​(int p)
      Returns the p-norm of the vectorized array.
      double norm​(Double p)
      Returns the p-norm of the vectorized array.
      Stream<T> parallelStream()
      Returns a parallel Stream with this collection as its source.
      NDArray<T> permuteDims​(int... permutation)
      Returns a view that references this NDArray as parent, but the order of dimensions are swiched in this view.
      T prod()
      Returns the product of all elements in this NDArray.
      NDArray<T> prod​(int... selectedDims)
      Returns the product of all elements along the specified dimensions in this NDArray.
      NDArray<T> reduceSlices​(BiFunction<NDArray<T>,​int[],​T> func, int... selectedDims)
      Reduces slices along the specified dimensions in this NDArray to scalar values, reducing the number of dimensions.
      NDArray<T> reshape​(int... newShape)
      Returns a view that references this NDArray as parent but has a different shape.
      NDArray<T> selectDims​(int... selectedDims)
      Returns a view that references this NDArray as parent, and skips all singleton dimensions not included in the parameter list.
      void set​(Number value, int linearIndex)
      Sets the value of an element specified by linear indexing.
      void set​(Number value, int... indices)
      Sets the value of an element specified by cartesian indexing.
      void set​(T value, int linearIndex)
      Sets the value of an element specified by linear indexing.
      void set​(T value, int... indices)
      Sets the value of an element specified by cartesian indexing.
      int[] shape()
      Returns the dimensions of the array.
      int shape​(int axis)
      Returns the shape of the array along a specific dimension/axis.
      NDArray<T> similar()
      Returns a new array of the same shape as this NDArray filled with zeros.
      NDArray<T> slice​(Object... slicingExpressions)
      Returns an array view referencing this NDArray as parent that gives read-write access to a specific multi-dimensional slice of the array.
      Spliterator<T> spliterator()
      Creates a Spliterator over the elements in this collection.
      NDArray<T> squeeze()
      Returns a view that references this NDArray as parent, and skips all singleton dimensions.
      Stream<T> stream()
      Returns a sequential Stream with this collection as its source.
      Stream<int[]> streamCartesianIndices()
      Returns a stream of cartesian indices.
      static Stream<int[]> streamCartesianIndices​(int... shape)
      Returns a stream of int arrays that represent all Cartesian indices of a virtual n-dimensional array with the specified shape.
      IntStream streamLinearIndices()
      Returns a stream of linear indices.
      default NDArray<T> subtract​(byte subtrahend)
      Creates a new NDArray of the same shape and fills it with the values of this NDArray minus the given value.
      default NDArray<T> subtract​(double subtrahend)
      Creates a new NDArray of the same shape and fills it with the values of this NDArray minus the given value.
      default NDArray<T> subtract​(float subtrahend)
      Creates a new NDArray of the same shape and fills it with the values of this NDArray minus the given value.
      default NDArray<T> subtract​(int subtrahend)
      Creates a new NDArray of the same shape and fills it with the values of this NDArray minus the given value.
      default NDArray<T> subtract​(long subtrahend)
      Creates a new NDArray of the same shape and fills it with the values of this NDArray minus the given value.
      default NDArray<T> subtract​(short subtrahend)
      Creates a new NDArray of the same shape and fills it with the values of this NDArray minus the given value.
      default NDArray<T> subtract​(NDArray<?> subtrahend)
      Creates a new NDArray of the same shape and fills it with the element-wise subtraction of the given NDArray from this NDArray.
      NDArray<T> subtract​(Object... subtrahends)
      Creates a new NDArray of the same shape and fills it with the result of the element-wise substraction the parameter NDArrays and scalars from this NDArray.
      default NDArray<T> subtractInplace​(byte subtrahend)
      Updates this NDArray by subtracting the given value from all entries of this NDArray.
      default NDArray<T> subtractInplace​(double subtrahend)
      Updates this NDArray by subtracting the given value from all entries of this NDArray.
      default NDArray<T> subtractInplace​(float subtrahend)
      Updates this NDArray by subtracting the given value from all entries of this NDArray.
      default NDArray<T> subtractInplace​(int subtrahend)
      Updates this NDArray by subtracting the given value from all entries of this NDArray.
      default NDArray<T> subtractInplace​(long subtrahend)
      Updates this NDArray by subtracting the given value from all entries of this NDArray.
      default NDArray<T> subtractInplace​(short subtrahend)
      Updates this NDArray by subtracting the given value from all entries of this NDArray.
      default NDArray<T> subtractInplace​(NDArray<?> subtrahend)
      Updates this NDArray with the element-wise subtraction of the given NDArray from this NDArray.
      NDArray<T> subtractInplace​(Object... subtrahends)
      Updates the elements this NDArray with the result of the element-wise subtraction the parameter NDArrays and scalars from this NDArray.
      T sum()
      Returns the sum of all elements in this NDArray.
      NDArray<T> sum​(int... selectedDims)
      Returns the sum of all elements along the specified dimensions in this NDArray.
      Object[] toArray()
      Returns an array containing all of the elements in this collection.
      <A> A toArray​(A array)
      Returns an array containing all of the elements in this collection; the runtime type of the returned array is that of the specified array.
      <A> A toArray​(IntFunction<A> generator)
      Returns an array containing all of the elements in this collection, using the provided generator function to allocate the returned array.
      String toString()
      Returns a String containing type and shape information.
      void writeToFile​(File file)
      Save content of the NDArray to the given file.
    • Method Detail

      • streamCartesianIndices

        static Stream<int[]> streamCartesianIndices​(int... shape)
        Returns a stream of int arrays that represent all Cartesian indices of a virtual n-dimensional array with the specified shape.
        Parameters:
        shape - Shape of the virtual n-dimensional array for which Cartesian indices are streamed
        Returns:
        a stream of int arrays that represent all Cartesian indices of a virtual NDArray
      • getNamePrefix

        String getNamePrefix()
        Returns a string that identifies the implementation behind this current object. The output of the toString() function starts with this string.
        Returns:
        a string that identifies the implementation
      • length

        int length()
        Returns the number of elements within this NDArray.
        Returns:
        the number of elements in this collection
      • ndim

        int ndim()
        Returns the number of dimensions.
        Returns:
        the number of dimensions
      • shape

        int[] shape()
        Returns the dimensions of the array.
        Returns:
        the dimensions of the array
      • shape

        int shape​(int axis)
        Returns the shape of the array along a specific dimension/axis.
        Parameters:
        axis - Selected dimension/axis
        Returns:
        the shape of the array along a specific dimension/axis
      • dtype

        Class<?> dtype()
        Returns the type of values returned by get method. Possible values: Float.class, Double.class, Complex.class Byte.class, Short.class, Integer.class, Long.class.
        Returns:
        the type of values returned by get method.
      • equals

        boolean equals​(Object obj)
        Compares the specified object with this NDArray for equality. Two arrays are equal, if they are both real or both complex, and they are element-wise equal. If the specified object is not NDArray then the function returns false.
        Overrides:
        equals in class Object
        Parameters:
        obj - Object to be compared for equality
        Returns:
        true if the specified object equals with this NDArray
      • hashCode

        int hashCode()
        This method is unsupported because NDArrays should not be used as keys in hash-based collections.
        Overrides:
        hashCode in class Object
        Returns:
        always throws UnsupportedOperationsException
      • iterator

        Iterator<T> iterator()
        Returns an iterator over the elements in this collection. The iteration is done in column-first order similarly to linear indexing. This function is most likely not used directly, but it is required to be overloaded in order to make streaming of elements possible.
        Specified by:
        iterator in interface Iterable<T>
        Returns:
        an Iterator over the elements in this collection
      • spliterator

        Spliterator<T> spliterator()
        Creates a Spliterator over the elements in this collection. The iteration is done in column-first order similarly to linear indexing, and the splits are done equally on the remaining elements. This function is most likely not used directly, but it is required to be overloaded in order to make parallel streaming of elements possible.
        Specified by:
        spliterator in interface Iterable<T>
        Returns:
        a Spliterator over the elements in this collection
      • stream

        Stream<T> stream()
        Returns a sequential Stream with this collection as its source.
        Returns:
        a sequential Stream with this collection as its source.
      • parallelStream

        Stream<T> parallelStream()
        Returns a parallel Stream with this collection as its source.
        Returns:
        a parallel Stream with this collection as its source.
      • get

        T get​(int linearIndex)
        Returns an element specified by linear indexing.

        Linear indexing: It selects the ith element using the column-major iteration order that linearly spans the entire array.

        Negative indexing is supported, e.g. -1 refers to the last element, -2 refers to the item before the last one, etc.

        Parameters:
        linearIndex - linear coordinates
        Returns:
        an element specified by cartesian indexing
      • get

        T get​(int... indices)
        Returns an element specified by cartesian indexing.

        Cartesian indexing: The ordinary way to index into an N-dimensional array is to use exactly N indices; each index selects the position(s) in its particular dimension.

        Negative indexing is supported, e.g. assuming a 3×4 NDArray, index [2,-1] equals to [2,3], and [-1,-3] is an equivalent of [2,1].

        Parameters:
        indices - cartesian coordinates
        Returns:
        an element specified by cartesian indexing
      • set

        void set​(Number value,
                 int linearIndex)
        Sets the value of an element specified by linear indexing.

        Linear indexing: It selects the ith element using the column-major iteration order that linearly spans the entire array. in its particular dimension.

        Negative indexing is supported, e.g. -1 refers to the last element, -2 refers to the item before the last one, etc.

        Parameters:
        value - value to be assigned
        linearIndex - linear coordinates
      • set

        void set​(T value,
                 int linearIndex)
        Sets the value of an element specified by linear indexing.

        Linear indexing: It selects the ith element using the column-major iteration order that linearly spans the entire array. in its particular dimension.

        Negative indexing is supported, e.g. -1 refers to the last element, -2 refers to the item before the last one, etc.

        Parameters:
        value - value to be assigned
        linearIndex - linear coordinates
      • set

        void set​(Number value,
                 int... indices)
        Sets the value of an element specified by cartesian indexing.

        Cartesian indexing: The ordinary way to index into an N-dimensional array is to use exactly N indices; each index selects the position(s) in its particular dimension.

        Negative indexing is supported, e.g. assuming a 3×4 NDArray, index [2,-1] equals to [2,3], and [-1,-3] is an equivalent of [2,1].

        Parameters:
        value - value to be assigned
        indices - cartesian coordinates
      • set

        void set​(T value,
                 int... indices)
        Sets the value of an element specified by cartesian indexing.

        Cartesian indexing: The ordinary way to index into an N-dimensional array is to use exactly N indices; each index selects the position(s) in its particular dimension.

        Negative indexing is supported, e.g. assuming a 3×4 NDArray, index [2,-1] equals to [2,3], and [-1,-3] is an equivalent of [2,1].

        Parameters:
        value - value to be assigned
        indices - cartesian coordinates
      • contains

        boolean contains​(Object o)
      • copyFrom

        NDArray<T> copyFrom​(NDArray<?> array)
        Updates this NDArray with the elements of the NDArray given as parameter.

        Note: the parameter NDArray must have the same shape and this NDArray!

        Parameters:
        array - NDArray from which values are copied to this NDArray
        Returns:
        this NDArray
      • copyFrom

        NDArray<T> copyFrom​(byte[] array)
        Updates this NDArray with the elements of the array given as parameter.

        Note: the parameter array must have the same shape and this NDArray!

        Parameters:
        array - array holding the new values to be copied to this NDArray
        Returns:
        this NDArray
      • copyFrom

        NDArray<T> copyFrom​(short[] array)
        Updates this NDArray with the elements of the array given as parameter.

        Note: the parameter array must have the same shape and this NDArray!

        Parameters:
        array - array holding the new values to be copied to this NDArray
        Returns:
        this NDArray
      • copyFrom

        NDArray<T> copyFrom​(int[] array)
        Updates this NDArray with the elements of the array given as parameter.

        Note: the parameter array must have the same shape and this NDArray!

        Parameters:
        array - array holding the new values to be copied to this NDArray
        Returns:
        this NDArray
      • copyFrom

        NDArray<T> copyFrom​(long[] array)
        Updates this NDArray with the elements of the array given as parameter.

        Note: the parameter array must have the same shape and this NDArray!

        Parameters:
        array - array holding the new values to be copied to this NDArray
        Returns:
        this NDArray
      • copyFrom

        NDArray<T> copyFrom​(float[] array)
        Updates this NDArray with the elements of the array given as parameter.

        Note: the parameter array must have the same shape and this NDArray!

        Parameters:
        array - array holding the new values to be copied to this NDArray
        Returns:
        this NDArray
      • copyFrom

        NDArray<T> copyFrom​(double[] array)
        Updates this NDArray with the elements of the array given as parameter.

        Note: the parameter array must have the same shape and this NDArray!

        Parameters:
        array - array holding the new values to be copied to this NDArray
        Returns:
        this NDArray
      • copyFrom

        NDArray<T> copyFrom​(Object[] array)
        Updates this NDArray with the elements of the array given as parameter.

        Note: the parameter array must have the same shape and this NDArray!

        Parameters:
        array - array holding the new values to be copied to this NDArray
        Returns:
        this NDArray
      • fillUsingLinearIndices

        NDArray<T> fillUsingLinearIndices​(IntFunction<T> func)
        Apply the given function to each element of the array, and override each entry with the calculated new values. Please note that entries might not be processed in a sequential order!
        Parameters:
        func - function that receives the linear index of the current entry, and returns the new value
        Returns:
        itself after the update
      • fillUsingCartesianIndices

        NDArray<T> fillUsingCartesianIndices​(Function<int[],​T> func)
        Apply the given function to each element of the array, and override each entry with the calculated new values. Please note that entries might not be processed in a sequential order!
        Parameters:
        func - function that receives the Cartesian coordinate of the current entry, and returns the new value
        Returns:
        itself after the update
      • apply

        NDArray<T> apply​(UnaryOperator<T> func)
        Apply the given function to each element of the array, and override each entry with the calculated new values. Please note that entries might not be processed in a sequential order!
        Parameters:
        func - function that receives the value of the current entry, and returns the new value
        Returns:
        itself after the update
      • applyWithLinearIndices

        NDArray<T> applyWithLinearIndices​(BiFunction<T,​Integer,​T> func)
        Apply the given function to each element of the array, and override each entry with the calculated new values. Please note that entries might not be processed in a sequential order!
        Parameters:
        func - function that receives the value of the current entry and its linear index, and returns the new value
        Returns:
        itself after the update
      • applyWithCartesianIndices

        NDArray<T> applyWithCartesianIndices​(BiFunction<T,​int[],​T> func)
        Apply the given function to each element of the array, and override each entry with the calculated new values. Please note that entries might not be processed in a sequential order!
        Parameters:
        func - function that receives the value of the current entry and its Cartesian coordinate, and returns the new value
        Returns:
        itself after the update
      • applyOnSlices

        NDArray<T> applyOnSlices​(BiFunction<NDArray<T>,​int[],​NDArray<?>> func,
                                 int... iterationDims)
        Apply the given function to each slices of the array, and override each entry with the returned slice. Please note that slices might not be processed in a sequential order!
        Parameters:
        func - function that receives the value of the current entry and its Cartesian coordinate, and returns a slice from which values are copied to original array
        iterationDims - dimensions along which iteration is performed
        Returns:
        itself after the update
      • map

        NDArray<T> map​(UnaryOperator<T> func)
        Apply the given function to each element of the array, and create a new NDArray with the calculated new values. Please note that entries might not be processed in a sequential order!
        Parameters:
        func - function that receives the value of the current entry, and returns the new value
        Returns:
        the new NDArray with the calculated new values
      • mapWithLinearIndices

        NDArray<T> mapWithLinearIndices​(BiFunction<T,​Integer,​T> func)
        Apply the given function to each element of the array, and create a new NDArray with the calculated new values. Please note that entries might not be processed in a sequential order!
        Parameters:
        func - function that receives the value of the current entry and its linear index, and returns the new value
        Returns:
        the new NDArray with the calculated new values
      • mapWithCartesianIndices

        NDArray<T> mapWithCartesianIndices​(BiFunction<T,​int[],​T> func)
        Apply the given function to each element of the array, and create a new NDArray with the calculated new values. Please note that entries might not be processed in a sequential order!
        Parameters:
        func - function that receives the value of the current entry and its Cartesian coordinate, and returns the new value
        Returns:
        the new NDArray with the calculated new values
      • mapOnSlices

        NDArray<T> mapOnSlices​(BiFunction<NDArray<T>,​int[],​NDArray<?>> func,
                               int... iterationDims)
        Apply the given function to each slices of the array, and create a new NDArray with the calculated new values. Please note that slices might not be processed in a sequential order!
        Parameters:
        func - function that receives slice and its Cartesian coordinate along the iteration dimensions, and returns a new array with the same size as the slice
        iterationDims - dimensions along which iteration is performed
        Returns:
        the new NDArray with the calculated new values
      • forEach

        void forEach​(Consumer<? super T> func)
        Apply the given function to each element of the array, and override each entry with the calculated new values. Please note that entries might not be processed in a sequential order!
        Specified by:
        forEach in interface Iterable<T>
        Parameters:
        func - function that receives the value of the current entry
      • forEachWithLinearIndices

        void forEachWithLinearIndices​(ObjIntConsumer<T> func)
        Apply the given function to each element of the array, and override each entry with the calculated new values. Please note that entries might not be processed in a sequential order!
        Parameters:
        func - function that receives the value of the current entry and its linear index
      • forEachWithCartesianIndices

        void forEachWithCartesianIndices​(BiConsumer<T,​int[]> func)
        Apply the given function to each element of the array, and override each entry with the calculated new values. Please note that entries might not be processed in a sequential order!
        Parameters:
        func - function that receives the value of the current entry and its Cartesian coordinate
      • toArray

        Object[] toArray()
        Returns an array containing all of the elements in this collection. If this collection makes any guarantees as to what order its elements are returned by its iterator, this method must return the elements in the same order. The returned array's runtime component type is Object.

        The returned array will be "safe" in that no references to it are maintained by this collection. (In other words, this method must allocate a new array even if this collection is backed by an array). The caller is thus free to modify the returned array.

        Returns:
        an array, whose runtime component type is Object, containing all of the elements in this collection
      • toArray

        <A> A toArray​(A array)
        Returns an array containing all of the elements in this collection; the runtime type of the returned array is that of the specified array. If the collection fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the shape of this collection.

        If this collection fits in the specified array with room to spare (i.e., the array has more elements than this collection), the element in the array immediately following the end of the collection is set to null. (This is useful in determining the length of this collection only if the caller knows that this collection does not contain any null elements.)

        If this collection makes any guarantees as to what order its elements are returned by its iterator, this method must return the elements in the same order.

        Type Parameters:
        A - the component type of the array to contain the collection
        Parameters:
        array - the array into which the elements of this collection are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose.
        Returns:
        an array containing all of the elements in this collection
      • toArray

        <A> A toArray​(IntFunction<A> generator)
        Returns an array containing all of the elements in this collection, using the provided generator function to allocate the returned array.

        If this collection makes any guarantees as to what order its elements are returned by its iterator, this method must return the elements in the same order.

        Type Parameters:
        A - the component type of the array to contain the collection
        Parameters:
        generator - a function which produces a new array of the desired type and the provided length
        Returns:
        an array containing all of the elements in this collection
      • toString

        String toString()
        Returns a String containing type and shape information.
        Overrides:
        toString in class Object
        Returns:
        a String containing type and shape information.
      • contentToString

        String contentToString()
        Returns a String containing tabular representation of the array. For arrays that have more than 2 dimensions, the function prints 2D slices and iterates over all other dimensions incrementally. Note: this function might produce enormous output as it doesn't truncate result even for large arrays!
        Returns:
        a String containing tabular representation of the array.
      • contentToString

        String contentToString​(String format)
        Returns a String containing tabular representation of the array. For arrays that have more than 2 dimensions, the function prints 2D slices and iterates over all other dimensions incrementally. Note: this function might produce enormous output as it doesn't truncate result even for large arrays!
        Parameters:
        format - format specifier for individual elements (e.g. 5.3f)
        Returns:
        a String containing tabular representation of the array.
      • dataTypeAsString

        String dataTypeAsString()
        Returns a String representation of element type.
        Returns:
        "Byte", "Short", "Integer", "Long", "Float", "Double", "Complex Float", or "Complex Double" depending on the type of array
      • add

        default NDArray<T> add​(byte addend)
        Creates a new NDArray of the same shape and fills it with the values of this NDArray incremented by the given value.

        Note: The type of this NDArray determines type of the resulting NDArray.

        Parameters:
        addend - scalar value to be added to each element of the NDArray
        Returns:
        a new NDArray of the same shape and fills it with the values of this NDArray incremented by the given value
      • add

        default NDArray<T> add​(short addend)
        Creates a new NDArray of the same shape and fills it with the values of this NDArray incremented by the given value.

        Note: The type of this NDArray determines type of the resulting NDArray.

        Parameters:
        addend - scalar value to be added to each element of the NDArray
        Returns:
        a new NDArray of the same shape and fills it with the values of this NDArray incremented by the given value
      • add

        default NDArray<T> add​(int addend)
        Creates a new NDArray of the same shape and fills it with the values of this NDArray incremented by the given value.

        Note: The type of this NDArray determines type of the resulting NDArray.

        Parameters:
        addend - scalar value to be added to each element of the NDArray
        Returns:
        a new NDArray of the same shape and fills it with the values of this NDArray incremented by the given value
      • add

        default NDArray<T> add​(long addend)
        Creates a new NDArray of the same shape and fills it with the values of this NDArray incremented by the given value.

        Note: The type of this NDArray determines type of the resulting NDArray.

        Parameters:
        addend - scalar value to be added to each element of the NDArray
        Returns:
        a new NDArray of the same shape and fills it with the values of this NDArray incremented by the given value
      • add

        default NDArray<T> add​(float addend)
        Creates a new NDArray of the same shape and fills it with the values of this NDArray incremented by the given value.

        Note: The type of this NDArray determines type of the resulting NDArray.

        Parameters:
        addend - scalar value to be added to each element of the NDArray
        Returns:
        a new NDArray of the same shape and fills it with the values of this NDArray incremented by the given value
      • add

        default NDArray<T> add​(double addend)
        Creates a new NDArray of the same shape and fills it with the values of this NDArray incremented by the given value.

        Note: The type of this NDArray determines type of the resulting NDArray.

        Parameters:
        addend - scalar value to be added to each element of the NDArray
        Returns:
        a new NDArray of the same shape and fills it with the values of this NDArray incremented by the given value
      • add

        default NDArray<T> add​(NDArray<?> addend)
        Creates a new NDArray of the same shape and fills it with the element-wise sum of this NDArray and the NDArray given as parameter.

        Note: The type of this NDArray determines type of the resulting NDArray.

        Parameters:
        addend - NDArray to be added to this NDArray
        Returns:
        a new NDArray of the same shape and fills it with the element-wise sum of this NDArray and the NDArray given as parameter.
      • add

        NDArray<T> add​(Object... addends)
        Creates a new NDArray of the same shape and fills it with the element-wise sum of this NDArray and the parameter NDArrays and scalars. If list of parameters contains scalar values than these will be added to all elements of the resulting array.

        Note: The type of this NDArray determines type of the resulting NDArray.

        Parameters:
        addends - NDArrays and scalars to be added to this NDArray
        Returns:
        a new NDArray of the same shape, and fills it with the element-wise sum of this NDArray and the parameters NDArrays and scalars
      • addInplace

        default NDArray<T> addInplace​(byte addend)
        Updates this NDArray by incrementing all entries with the given value.

        Note: The type of this NDArray determines type of the resulting NDArray.

        Parameters:
        addend - scalar value to be added to each element of the NDArray
        Returns:
        this NDArray after addition
      • addInplace

        default NDArray<T> addInplace​(short addend)
        Updates this NDArray by incrementing all entries with the given value.

        Note: The type of this NDArray determines type of the resulting NDArray.

        Parameters:
        addend - scalar value to be added to each element of the NDArray
        Returns:
        this NDArray after addition
      • addInplace

        default NDArray<T> addInplace​(int addend)
        Updates this NDArray by incrementing all entries with the given value.

        Note: The type of this NDArray determines type of the resulting NDArray.

        Parameters:
        addend - scalar value to be added to each element of the NDArray
        Returns:
        this NDArray after addition
      • addInplace

        default NDArray<T> addInplace​(long addend)
        Updates this NDArray by incrementing all entries with the given value.

        Note: The type of this NDArray determines type of the resulting NDArray.

        Parameters:
        addend - scalar value to be added to each element of the NDArray
        Returns:
        this NDArray after addition
      • addInplace

        default NDArray<T> addInplace​(float addend)
        Updates this NDArray by incrementing all entries with the given value.

        Note: The type of this NDArray determines type of the resulting NDArray.

        Parameters:
        addend - scalar value to be added to each element of the NDArray
        Returns:
        this NDArray after addition
      • addInplace

        default NDArray<T> addInplace​(double addend)
        Updates this NDArray by incrementing all entries with the given value.

        Note: The type of this NDArray determines type of the resulting NDArray.

        Parameters:
        addend - scalar value to be added to each element of the NDArray
        Returns:
        this NDArray after addition
      • addInplace

        default NDArray<T> addInplace​(NDArray<?> addend)
        Updates this NDArray with the element-wise sum of this NDArray and the one given as parameter.

        Note: The type of this NDArray determines type of the resulting NDArray.

        Parameters:
        addend - NDArray to be added to this NDArray
        Returns:
        this NDArray after addition
      • addInplace

        NDArray<T> addInplace​(Object... addends)
        Updates this NDArray with the element-wise sum of this NDArray and the ones given as parameters. The list of parameters can also contain scalar values - these will be added to all elements of the resulting array.

        Note: The type of this NDArray determines type of the resulting NDArray.

        Parameters:
        addends - NDArrays and scalars to be added to this NDArray
        Returns:
        this NDArray after addition
      • subtract

        default NDArray<T> subtract​(byte subtrahend)
        Creates a new NDArray of the same shape and fills it with the values of this NDArray minus the given value.

        Note: The type of this NDArray determines type of the resulting NDArray.

        Parameters:
        subtrahend - scalar value to be subtracted from each element of the NDArray
        Returns:
        a new NDArray of the same shape and fills it with the values of this NDArray minus the given value
      • subtract

        default NDArray<T> subtract​(short subtrahend)
        Creates a new NDArray of the same shape and fills it with the values of this NDArray minus the given value.

        Note: The type of this NDArray determines type of the resulting NDArray.

        Parameters:
        subtrahend - scalar value to be subtracted from each element of the NDArray
        Returns:
        a new NDArray of the same shape and fills it with the values of this NDArray minus the given value
      • subtract

        default NDArray<T> subtract​(int subtrahend)
        Creates a new NDArray of the same shape and fills it with the values of this NDArray minus the given value.

        Note: The type of this NDArray determines type of the resulting NDArray.

        Parameters:
        subtrahend - scalar value to be subtracted from each element of the NDArray
        Returns:
        a new NDArray of the same shape and fills it with the values of this NDArray minus the given value
      • subtract

        default NDArray<T> subtract​(long subtrahend)
        Creates a new NDArray of the same shape and fills it with the values of this NDArray minus the given value.

        Note: The type of this NDArray determines type of the resulting NDArray.

        Parameters:
        subtrahend - scalar value to be subtracted from each element of the NDArray
        Returns:
        a new NDArray of the same shape and fills it with the values of this NDArray minus the given value
      • subtract

        default NDArray<T> subtract​(float subtrahend)
        Creates a new NDArray of the same shape and fills it with the values of this NDArray minus the given value.

        Note: The type of this NDArray determines type of the resulting NDArray.

        Parameters:
        subtrahend - scalar value to be subtracted from each element of the NDArray
        Returns:
        a new NDArray of the same shape and fills it with the values of this NDArray minus the given value
      • subtract

        default NDArray<T> subtract​(double subtrahend)
        Creates a new NDArray of the same shape and fills it with the values of this NDArray minus the given value.

        Note: The type of this NDArray determines type of the resulting NDArray.

        Parameters:
        subtrahend - scalar value to be subtracted from each element of the NDArray
        Returns:
        a new NDArray of the same shape and fills it with the values of this NDArray minus the given value
      • subtract

        default NDArray<T> subtract​(NDArray<?> subtrahend)
        Creates a new NDArray of the same shape and fills it with the element-wise subtraction of the given NDArray from this NDArray.

        Note: The type of this NDArray determines type of the resulting NDArray.

        Parameters:
        subtrahend - NDArray to be subtracted from this NDArray
        Returns:
        a new NDArray filled with the element-wise subtraction of the given NDArray from this NDArray.
      • subtract

        NDArray<T> subtract​(Object... subtrahends)
        Creates a new NDArray of the same shape and fills it with the result of the element-wise substraction the parameter NDArrays and scalars from this NDArray. If list of parameters contains scalar values than these will be substracted from all elements of this NDArray.

        Note: The type of this NDArray determines type of the resulting NDArray.

        Parameters:
        subtrahends - NDArrays and scalars to be substracted from this NDArray
        Returns:
        a new NDArray filled with the result of the element-wise substraction of the parameter NDArrays and scalars from this NDArray
      • subtractInplace

        default NDArray<T> subtractInplace​(byte subtrahend)
        Updates this NDArray by subtracting the given value from all entries of this NDArray.

        Note: The type of this NDArray determines type of the resulting NDArray.

        Parameters:
        subtrahend - scalar value to be subtracted from each element of the NDArray
        Returns:
        this NDArray after subtraction
      • subtractInplace

        default NDArray<T> subtractInplace​(short subtrahend)
        Updates this NDArray by subtracting the given value from all entries of this NDArray.

        Note: The type of this NDArray determines type of the resulting NDArray.

        Parameters:
        subtrahend - scalar value to be subtracted from each element of the NDArray
        Returns:
        this NDArray after subtraction
      • subtractInplace

        default NDArray<T> subtractInplace​(int subtrahend)
        Updates this NDArray by subtracting the given value from all entries of this NDArray.

        Note: The type of this NDArray determines type of the resulting NDArray.

        Parameters:
        subtrahend - scalar value to be subtracted from each element of the NDArray
        Returns:
        this NDArray after subtraction
      • subtractInplace

        default NDArray<T> subtractInplace​(long subtrahend)
        Updates this NDArray by subtracting the given value from all entries of this NDArray.

        Note: The type of this NDArray determines type of the resulting NDArray.

        Parameters:
        subtrahend - scalar value to be subtracted from each element of the NDArray
        Returns:
        this NDArray after subtraction
      • subtractInplace

        default NDArray<T> subtractInplace​(float subtrahend)
        Updates this NDArray by subtracting the given value from all entries of this NDArray.

        Note: The type of this NDArray determines type of the resulting NDArray.

        Parameters:
        subtrahend - scalar value to be subtracted from each element of the NDArray
        Returns:
        this NDArray after subtraction
      • subtractInplace

        default NDArray<T> subtractInplace​(double subtrahend)
        Updates this NDArray by subtracting the given value from all entries of this NDArray.

        Note: The type of this NDArray determines type of the resulting NDArray.

        Parameters:
        subtrahend - scalar value to be subtracted from each element of the NDArray
        Returns:
        this NDArray after subtraction
      • subtractInplace

        default NDArray<T> subtractInplace​(NDArray<?> subtrahend)
        Updates this NDArray with the element-wise subtraction of the given NDArray from this NDArray.

        Note: The type of this NDArray determines type of the resulting NDArray.

        Parameters:
        subtrahend - NDArray to be subtracted from this NDArray
        Returns:
        this NDArray after subtraction
      • subtractInplace

        NDArray<T> subtractInplace​(Object... subtrahends)
        Updates the elements this NDArray with the result of the element-wise subtraction the parameter NDArrays and scalars from this NDArray. If list of parameters contains scalar values than these will be substracted from all elements of this NDArray.

        Note: The type of this NDArray determines type of the resulting NDArray.

        Parameters:
        subtrahends - NDArrays and scalars to be substracted from this NDArray
        Returns:
        this NDArray after substraction
      • multiply

        default NDArray<T> multiply​(byte multiplicand)
        Creates a new NDArray of the same shape and fills it with the values of this NDArray multiplied by the given value.

        Note: The type of this NDArray determines type of the resulting NDArray.

        Parameters:
        multiplicand - scalar value with which each element of the NDArray are multiplied
        Returns:
        a new NDArray of the same shape and fills it with the values of this NDArray multiplied by the given value
      • multiply

        default NDArray<T> multiply​(short multiplicand)
        Creates a new NDArray of the same shape and fills it with the values of this NDArray multiplied by the given value.

        Note: The type of this NDArray determines type of the resulting NDArray.

        Parameters:
        multiplicand - scalar value with which each element of the NDArray are multiplied
        Returns:
        a new NDArray of the same shape and fills it with the values of this NDArray multiplied by the given value
      • multiply

        default NDArray<T> multiply​(int multiplicand)
        Creates a new NDArray of the same shape and fills it with the values of this NDArray multiplied by the given value.

        Note: The type of this NDArray determines type of the resulting NDArray.

        Parameters:
        multiplicand - scalar value with which each element of the NDArray are multiplied
        Returns:
        a new NDArray of the same shape and fills it with the values of this NDArray multiplied by the given value
      • multiply

        default NDArray<T> multiply​(long multiplicand)
        Creates a new NDArray of the same shape and fills it with the values of this NDArray multiplied by the given value.

        Note: The type of this NDArray determines type of the resulting NDArray.

        Parameters:
        multiplicand - scalar value with which each element of the NDArray are multiplied
        Returns:
        a new NDArray of the same shape and fills it with the values of this NDArray multiplied by the given value
      • multiply

        default NDArray<T> multiply​(float multiplicand)
        Creates a new NDArray of the same shape and fills it with the values of this NDArray multiplied by the given value.

        Note: The type of this NDArray determines type of the resulting NDArray.

        Parameters:
        multiplicand - scalar value with which each element of the NDArray are multiplied
        Returns:
        a new NDArray of the same shape and fills it with the values of this NDArray multiplied by the given value
      • multiply

        default NDArray<T> multiply​(double multiplicand)
        Creates a new NDArray of the same shape and fills it with the values of this NDArray multiplied by the given value.

        Note: The type of this NDArray determines type of the resulting NDArray.

        Parameters:
        multiplicand - scalar value with which each element of the NDArray are multiplied
        Returns:
        a new NDArray of the same shape and fills it with the values of this NDArray multiplied by the given value
      • multiply

        default NDArray<T> multiply​(NDArray<?> multiplicand)
        Creates a new NDArray of the same shape and fills it with the element-wise product of this NDArray and the NDArray given as parameter.

        Note: The type of this NDArray determines type of the resulting NDArray.

        Parameters:
        multiplicand - NDArray to be multiplied with this NDArray
        Returns:
        a new NDArray of the same shape and fills it with the element-wise product of this NDArray and the NDArray given as parameter.
      • multiply

        NDArray<T> multiply​(Object... multiplicands)
        Creates a new NDArray of the same shape and fills it with the element-wise product of this NDArray and the parameter NDArrays and scalars. If list of parameters contains scalar values than these will be multiplied to all elements of the resulting array.

        Note: The type of this NDArray determines type of the resulting NDArray.

        Parameters:
        multiplicands - NDArrays and scalars to be multiplied together
        Returns:
        a new NDArray of the same shape, and fills it with the element-wise product of this NDArray and the parameters NDArrays and scalars
      • multiplyInplace

        default NDArray<T> multiplyInplace​(byte multiplicand)
        Updates the elements of this NDArray with the values of this NDArray multiplied by the given value.

        Note: The type of this NDArray determines type of the resulting NDArray.

        Parameters:
        multiplicand - scalar value with which each element of the NDArray are multiplied
        Returns:
        this NDArray after multiplication
      • multiplyInplace

        default NDArray<T> multiplyInplace​(short multiplicand)
        Updates the elements of this NDArray with the values of this NDArray multiplied by the given value.

        Note: The type of this NDArray determines type of the resulting NDArray.

        Parameters:
        multiplicand - scalar value with which each element of the NDArray are multiplied
        Returns:
        this NDArray after multiplication
      • multiplyInplace

        default NDArray<T> multiplyInplace​(int multiplicand)
        Updates the elements of this NDArray with the values of this NDArray multiplied by the given value.

        Note: The type of this NDArray determines type of the resulting NDArray.

        Parameters:
        multiplicand - scalar value with which each element of the NDArray are multiplied
        Returns:
        this NDArray after multiplication
      • multiplyInplace

        default NDArray<T> multiplyInplace​(long multiplicand)
        Updates the elements of this NDArray with the values of this NDArray multiplied by the given value.

        Note: The type of this NDArray determines type of the resulting NDArray.

        Parameters:
        multiplicand - scalar value with which each element of the NDArray are multiplied
        Returns:
        this NDArray after multiplication
      • multiplyInplace

        default NDArray<T> multiplyInplace​(float multiplicand)
        Updates the elements of this NDArray with the values of this NDArray multiplied by the given value.

        Note: The type of this NDArray determines type of the resulting NDArray.

        Parameters:
        multiplicand - scalar value with which each element of the NDArray are multiplied
        Returns:
        this NDArray after multiplication
      • multiplyInplace

        default NDArray<T> multiplyInplace​(double multiplicand)
        Updates the elements of this NDArray with the values of this NDArray multiplied by the given value.

        Note: The type of this NDArray determines type of the resulting NDArray.

        Parameters:
        multiplicand - scalar value with which each element of the NDArray are multiplied
        Returns:
        this NDArray after multiplication
      • multiplyInplace

        default NDArray<T> multiplyInplace​(NDArray<?> multiplicand)
        Updates the elements of this NDArray with the element-wise product of this NDArray and the NDArray given as parameter.

        Note: The type of this NDArray determines type of the resulting NDArray.

        Parameters:
        multiplicand - NDArray to be multiplied with this NDArray
        Returns:
        this NDArray after multiplication
      • multiplyInplace

        NDArray<T> multiplyInplace​(Object... multiplicands)
        Updates the elements of this NDArray with the element-wise product of this NDArray and the parameter NDArrays and scalars. If list of parameters contains scalar values than these will be multiplied to all elements of the resulting array.

        Note: The type of this NDArray determines type of the resulting NDArray.

        Parameters:
        multiplicands - NDArrays and scalars to be multiplied with this NDArray
        Returns:
        this NDArray after multiplication
      • divide

        default NDArray<T> divide​(byte divisor)
        Creates a new NDArray of the same shape and fills it with the values of this NDArray divided by the given value.

        Note: The type of this NDArray determines type of the resulting NDArray.

        Parameters:
        divisor - scalar value with which each element of the NDArray are divided
        Returns:
        a new NDArray of the same shape and fills it with the values of this NDArray divided by the given value
      • divide

        default NDArray<T> divide​(short divisor)
        Creates a new NDArray of the same shape and fills it with the values of this NDArray divided by the given value.

        Note: The type of this NDArray determines type of the resulting NDArray.

        Parameters:
        divisor - scalar value with which each element of the NDArray are divided
        Returns:
        a new NDArray of the same shape and fills it with the values of this NDArray divided by the given value
      • divide

        default NDArray<T> divide​(int divisor)
        Creates a new NDArray of the same shape and fills it with the values of this NDArray divided by the given value.

        Note: The type of this NDArray determines type of the resulting NDArray.

        Parameters:
        divisor - scalar value with which each element of the NDArray are divided
        Returns:
        a new NDArray of the same shape and fills it with the values of this NDArray divided by the given value
      • divide

        default NDArray<T> divide​(long divisor)
        Creates a new NDArray of the same shape and fills it with the values of this NDArray divided by the given value.

        Note: The type of this NDArray determines type of the resulting NDArray.

        Parameters:
        divisor - scalar value with which each element of the NDArray are divided
        Returns:
        a new NDArray of the same shape and fills it with the values of this NDArray divided by the given value
      • divide

        default NDArray<T> divide​(float divisor)
        Creates a new NDArray of the same shape and fills it with the values of this NDArray divided by the given value.

        Note: The type of this NDArray determines type of the resulting NDArray.

        Parameters:
        divisor - scalar value with which each element of the NDArray are divided
        Returns:
        a new NDArray of the same shape and fills it with the values of this NDArray divided by the given value
      • divide

        default NDArray<T> divide​(double divisor)
        Creates a new NDArray of the same shape and fills it with the values of this NDArray divided by the given value.

        Note: The type of this NDArray determines type of the resulting NDArray.

        Parameters:
        divisor - scalar value with which each element of the NDArray are divided
        Returns:
        a new NDArray of the same shape and fills it with the values of this NDArray divided by the given value
      • divide

        default NDArray<T> divide​(NDArray<?> divisor)
        Creates a new NDArray of the same shape and fills it with the element-wise division of this NDArray and the NDArray given as parameter.

        Note: The type of this NDArray determines type of the resulting NDArray.

        Parameters:
        divisor - divisor of this NDArray
        Returns:
        a new NDArray of the same shape and fills it with the element-wise division of this NDArray and the NDArray given as parameter.
      • divide

        NDArray<T> divide​(Object... divisors)
        Creates a new NDArray of the same shape and fills it with the result of the element-wise division of this NDArray by the parameter NDArrays and scalars. If list of parameters contains scalar values than all elements of this NDArray will be divided by them.

        Note: The type of this NDArray determines type of the resulting NDArray.

        Parameters:
        divisors - divisors of this NDArray
        Returns:
        a new NDArray of the same shape, and fills it with the result of the element-wise division of this NDArray by the parameter NDArrays and scalars
      • divideInplace

        default NDArray<T> divideInplace​(byte divisor)
        Updates the elements this NDArray with the values of this NDArray divided by the given value.

        Note: The type of this NDArray determines type of the resulting NDArray.

        Parameters:
        divisor - scalar value with which each element of the NDArray are divided
        Returns:
        this NDArray after division
      • divideInplace

        default NDArray<T> divideInplace​(short divisor)
        Updates the elements this NDArray with the values of this NDArray divided by the given value.

        Note: The type of this NDArray determines type of the resulting NDArray.

        Parameters:
        divisor - scalar value with which each element of the NDArray are divided
        Returns:
        this NDArray after division
      • divideInplace

        default NDArray<T> divideInplace​(int divisor)
        Updates the elements this NDArray with the values of this NDArray divided by the given value.

        Note: The type of this NDArray determines type of the resulting NDArray.

        Parameters:
        divisor - scalar value with which each element of the NDArray are divided
        Returns:
        this NDArray after division
      • divideInplace

        default NDArray<T> divideInplace​(long divisor)
        Updates the elements this NDArray with the values of this NDArray divided by the given value.

        Note: The type of this NDArray determines type of the resulting NDArray.

        Parameters:
        divisor - scalar value with which each element of the NDArray are divided
        Returns:
        this NDArray after division
      • divideInplace

        default NDArray<T> divideInplace​(float divisor)
        Updates the elements this NDArray with the values of this NDArray divided by the given value.

        Note: The type of this NDArray determines type of the resulting NDArray.

        Parameters:
        divisor - scalar value with which each element of the NDArray are divided
        Returns:
        this NDArray after division
      • divideInplace

        default NDArray<T> divideInplace​(double divisor)
        Updates the elements this NDArray with the values of this NDArray divided by the given value.

        Note: The type of this NDArray determines type of the resulting NDArray.

        Parameters:
        divisor - scalar value with which each element of the NDArray are divided
        Returns:
        this NDArray after division
      • divideInplace

        default NDArray<T> divideInplace​(NDArray<?> divisor)
        Updates the elements this NDArray with the element-wise division of this NDArray and the NDArray given as parameter.

        Note: The type of this NDArray determines type of the resulting NDArray.

        Parameters:
        divisor - divisor of this NDArray
        Returns:
        this NDArray after division
      • divideInplace

        NDArray<T> divideInplace​(Object... divisors)
        Updates the elements this NDArray with the result of the element-wise division of this NDArray by the parameter NDArrays and scalars. If list of parameters contains scalar values than all elements of this NDArray will be divided by them.

        Note: The type of this NDArray determines type of the resulting NDArray.

        Parameters:
        divisors - divisors of this NDArray
        Returns:
        this NDArray after division
      • sum

        T sum()
        Returns the sum of all elements in this NDArray.
        Returns:
        sum of all elements
      • sum

        NDArray<T> sum​(int... selectedDims)
        Returns the sum of all elements along the specified dimensions in this NDArray.

        For example, if A is a [5 × 8 × 3] array, then B = A.sum(2) returns a [5 × 8] array, and B.get(1,1) == A.get(1,1,0) + A.get(1,1,1) + A.get(1,1,2).

        Parameters:
        selectedDims - dimensions along which the summation should be performed
        Returns:
        sum of all elementsalong the specified dimensions
      • prod

        T prod()
        Returns the product of all elements in this NDArray.
        Returns:
        product of all elements
      • prod

        NDArray<T> prod​(int... selectedDims)
        Returns the product of all elements along the specified dimensions in this NDArray.

        For example, if A is a [5 × 8 × 3] array, then B = A.prod(2) returns a [5 × 8] array, and B.get(1,1) == A.get(1,1,0) * A.get(1,1,1) * A.get(1,1,2).

        Parameters:
        selectedDims - dimensions along which multiplication should be performed
        Returns:
        product of all elements along the specified dimensions
      • accumulate

        T accumulate​(BinaryOperator<T> func)
        Returns the result of accumulation of all elements in this NDArray.
        Parameters:
        func - accumulation function that accepts two elements and returns accumulation result
        Returns:
        result of accumulation
      • accumulate

        NDArray<T> accumulate​(BinaryOperator<T> func,
                              int... selectedDims)
        Returns the accumulation of all elements along the specified dimensions in this NDArray.

        For example, if A is a [5 × 8 × 3] array, then B = A.accumulate(func, 2) returns a [5 × 8] array, and B.get(1,1) == func(func(A.get(1,1,0), A.get(1,1,1)), A.get(1,1,2)).

        Parameters:
        func - accumulation function that accepts two elements and returns accumulation result
        selectedDims - dimensions along which the accumulation should be performed
        Returns:
        result of accumulation of all elements along the specified dimensions
      • reduceSlices

        NDArray<T> reduceSlices​(BiFunction<NDArray<T>,​int[],​T> func,
                                int... selectedDims)
        Reduces slices along the specified dimensions in this NDArray to scalar values, reducing the number of dimensions.

        For example, if A is a [5 × 8 × 3] array, then B = A.reduce(func, 2) returns a [5 × 8] array, and B.get(1,1) == func(A.slice(1, 1, ":"), new int[] { 1, 1 }).

        Parameters:
        func - reduction function that accepts a slice and its index and returns reduction result
        selectedDims - dimensions along which the reduction should be performed
        Returns:
        result of reduction of all slices along the specified dimensions
      • norm

        double norm()
        Returns the 2-norm (Euclidean norm) of the vectorized array.

        Note: All N-dimensional arrays are treated as if they were reshaped to a 1D vector.

        Returns:
        the 2-norm (Euclidean norm) of the vectorized array
      • norm

        default double norm​(int p)
        Returns the p-norm of the vectorized array.

        Note: All N-dimensional arrays are treated as if they were reshaped to a 1D vector.

        Possible values:
        • p = 0: Hamming distance of the vector from zero (number of non-zero entries) -- it is not a true norm!
        • 0 < p < 1: Hamming distance of the vector from zero (number of non-zero entries) -- it is only a quasi norm (triargument inequality doesn't hold)!
        • 1: Absolute-value norm (sum of the absolute values of the entries)
        • 2: Euclidean norm (square root of sum of the squared entry values)
        • 1 < p: General p-norm (Σ(|p|)ᵖ)^(1/p)
        • p = Double.POSITIVE_INFINITY: Infinity norm (returns the entry with the maximal absolute value)
        Parameters:
        p - type of norm
        Returns:
        the p-(quasi)norm of the array
      • norm

        double norm​(Double p)
        Returns the p-norm of the vectorized array.

        Note: All N-dimensional arrays are treated as if they were reshaped to a 1D vector.

        Possible values:
        • p = 0: Hamming distance of the vector from zero (number of non-zero entries) -- it is not a true norm!
        • 0 < p < 1: Hamming distance of the vector from zero (number of non-zero entries) -- it is only a quasi norm (triargument inequality doesn't hold)!
        • 1: Absolute-value norm (sum of the absolute values of the entries)
        • 2: Euclidean norm (square root of sum of the squared entry values)
        • 1 < p: General p-norm (Σ(|p|)ᵖ)^(1/p)
        • p = Double.POSITIVE_INFINITY: Infinity norm (returns the entry with the maximal absolute value)
        Parameters:
        p - type of norm
        Returns:
        the p-(quasi)norm of the array
      • fill

        NDArray<T> fill​(double value)
        Fill this NDArray with the specified value
        Parameters:
        value - value assigned to all elements of this NDArray
        Returns:
        this NDArray
      • fill

        NDArray<T> fill​(T value)
        Fill this NDArray with the specified value
        Parameters:
        value - value assigned to all elements of this NDArray
        Returns:
        this NDArray
      • similar

        NDArray<T> similar()
        Returns a new array of the same shape as this NDArray filled with zeros.
        Returns:
        a new array of the same shape as this NDArray filled with zeros.
      • copy

        NDArray<T> copy()
        Returns a copy of this NDArray.
        Returns:
        a copy of this NDArray.
      • selectDims

        NDArray<T> selectDims​(int... selectedDims)
        Returns a view that references this NDArray as parent, and skips all singleton dimensions not included in the parameter list.

        View: An NDArray that references the specified region its parent array. All modifications in the parent array are reflected in the view, and vice versa.

        Singleton dimension: dimension of shape 1.

        Parameters:
        selectedDims - dimensions kept in the returned view
        Returns:
        a view that references this NDArray as parent, and skips all singleton dimensions not included in the parameter list
      • dropDims

        NDArray<T> dropDims​(int... droppedDims)
        Returns a view that references this NDArray as parent, and skips all singleton dimensions included in the parameter list.

        View: An NDArray that references the specified region its parent array. All modifications in the parent array are reflected in the view, and vice versa.

        Singleton dimension: dimension of shape 1.

        Parameters:
        droppedDims - dimensions skipped in the returned view
        Returns:
        a view that references this NDArray as parent, and skips all singleton dimensions included in the parameter list
      • squeeze

        NDArray<T> squeeze()
        Returns a view that references this NDArray as parent, and skips all singleton dimensions.

        View: An NDArray that references the specified region its parent array. All modifications in the parent array are reflected in the view, and vice versa.

        Singleton dimension: dimension of shape 1.

        Returns:
        a view that references this NDArray as parent, and skips all singleton dimensions.
      • slice

        NDArray<T> slice​(Object... slicingExpressions)
        Returns an array view referencing this NDArray as parent that gives read-write access to a specific multi-dimensional slice of the array.

        View: An NDArray that references the specified region its parent array. All modifications in the parent array are reflected in the view, and vice versa.

        Possible slicing expressions:

        • integer values: selects a specific slice along the positionally selected dimension
        • range (string that consists of two integer values specifying the start and the end of the range separated by a colon): selects a specific range of slices along the positionally selected dimension
        • all-range (string literal ":" or Range.ALL): selects all slices along the positionally selected dimension

        For example, if A is a [5 × 8 × 3] array, then B = A.slice(1, "2:5", ":") returns a [3 × 3] array, and B.get(1,1) == A.get(1,3,1).

        Parameters:
        slicingExpressions - Slicing expressions
        Returns:
        an array view that gives read-write access to a specific multi-dimensional slice of the array
      • mask

        NDArray<T> mask​(NDArray<?> mask)
        Returns an array view referencing this NDArray as parent that gives read-write access to a specific elements of the array selected by the given mask. The mask must have the same shape as this array, and those entries are selected which has the same indices as the non-zero entries in the mask. In other words: All places where the mask contains a zero value are skipped, and all other values are copied into a new vector.
        Parameters:
        mask - NDArray in which non-zero entries marks elements to keep
        Returns:
        an array view that gives read-write access to a specific elements of the array selected by the given mask
      • inverseMask

        NDArray<T> inverseMask​(NDArray<?> inverseMask)
        Returns an array view referencing this NDArray as parent that gives read-write access to a specific elements of the array selected by the given inverseMask. The inverseMask must have the same shape as this array, and those entries are selected which has the same indices as the non-zero entries in the inverseMask. In other words: All places where the inverseMask contains a zero value are skipped, and all other values are copied into a new vector.
        Parameters:
        inverseMask - NDArray in which non-zero entries marks elements to keep
        Returns:
        an array view that gives read-write access to a specific elements of the array selected by the given inverseMask
      • mask

        NDArray<T> mask​(Predicate<T> func)
        Returns an array view referencing this NDArray as parent that gives read-write access to a specific elements for which the given function returns true.
        Parameters:
        func - function that accepts the values of entries as input and returns boolean
        Returns:
        an array view that gives read-write access to a specific elements for which the given function returns true
      • maskWithLinearIndices

        NDArray<T> maskWithLinearIndices​(BiPredicate<T,​Integer> func)
        Returns an array view referencing this NDArray as parent that gives read-write access to a specific elements for which the given function returns true.
        Parameters:
        func - function that accepts the values of entries and their linear indices as input and returns boolean
        Returns:
        an array view that gives read-write access to a specific elements for which the given function returns true
      • maskWithCartesianIndices

        NDArray<T> maskWithCartesianIndices​(BiPredicate<T,​int[]> func)
        Returns an array view referencing this NDArray as parent that gives read-write access to a specific elements for which the given function returns true.
        Parameters:
        func - function that accepts the values of entries and their Cartesian indices as input and returns boolean
        Returns:
        an array view that gives read-write access to a specific elements for which the given function returns true
      • reshape

        NDArray<T> reshape​(int... newShape)
        Returns a view that references this NDArray as parent but has a different shape.

        View: An NDArray that references the specified region its parent array. All modifications in the parent array are reflected in the view, and vice versa.

        For example, if A is a [5 × 8 × 3] array, then B = A.reshape(40, 3) returns a [40 × 3] array, and B.get(10) == B.get(10,0) == A.get(1,0,0) == A.get(10).

        Note: the linear indexing of the two arrays remain the same, and the corresponding cartesian indices determined by column-first ordering.

        Parameters:
        newShape - new shape/dimensions
        Returns:
        a view that references this NDArray as parent but has a different shape
      • permuteDims

        NDArray<T> permuteDims​(int... permutation)
        Returns a view that references this NDArray as parent, but the order of dimensions are swiched in this view.

        View: An NDArray that references the specified region its parent array. All modifications in the parent array are reflected in the view, and vice versa.

        For example, if A is a [5 × 8 × 3] array, then B = A.permuteDims(1, 0, 2) returns a [8 × 5 × 3] array, and B.get(3,1,0) == A.get(1,3,0).

        Parameters:
        permutation - new order of dimensions / permutation vector
        Returns:
        a view that references this NDArray as parent, but the order of dimensions are swiched in this view.
      • concatenate

        NDArray<T> concatenate​(int axis,
                               NDArray<?>... arrays)
        Creates a new NDArray that contains the elements of this NDArrays and all other NDArrays concatenated along the dimension/axis specified by the first parameter.
        Parameters:
        axis - Axis/dimension along which the concatenation should occur.
        arrays - Arrays to be concatenated to this NDArray.
        Returns:
        a new NDArray that contains the elements of this NDArrays and all other NDArrays concatenated along the dimension/axis specified by the first parameter.
      • streamLinearIndices

        IntStream streamLinearIndices()
        Returns a stream of linear indices.
        Returns:
        a stream of linear indices
      • streamCartesianIndices

        Stream<int[]> streamCartesianIndices()
        Returns a stream of cartesian indices. Each item in the stream is a int[] that holds cartesian indices.

        Cartesian indexing: The ordinary way to index into an N-dimensional array is to use exactly N indices; each index selects the position(s) in its particular dimension.

        Returns:
        a stream of cartesian indices
      • writeToFile

        void writeToFile​(File file)
                  throws IOException
        Save content of the NDArray to the given file.

        Files written that way can be later loaded by the static function readFromFile.

        • Example:
        
         
         NDArray<Float> array = new BasicFloatNDArray(128, 128).fill(5);
         array.writeToFile(new File("array.nda"));
         NDArray<Integer> array2 = BasicIntegerNDArray.readFromFile(new File("array.nda"));
         assertEquals(array, array2);
         
        Parameters:
        file - file into which the content of the NDArray is written (the extension of the file can be arbitrary, but .nda is recommended)
        Throws:
        IOException - when the given file cannot be opened for write