Interface RealNDArray<T extends Number>
-
- All Known Implementing Classes:
AbstractBigDecimalNDArray
,AbstractBigIntegerNDArray
,AbstractByteNDArray
,AbstractDoubleNDArray
,AbstractFloatNDArray
,AbstractIntegerNDArray
,AbstractLongNDArray
,AbstractRealNDArray
,AbstractShortNDArray
,BasicBigDecimalNDArray
,BasicBigIntegerNDArray
,BasicByteNDArray
,BasicDoubleNDArray
,BasicFloatNDArray
,BasicIntegerNDArray
,BasicLongNDArray
,BasicShortNDArray
,RealNDArrayMaskView
,RealNDArrayPermuteDimsView
,RealNDArrayReshapeView
,RealNDArraySliceView
public interface RealNDArray<T extends Number> extends NDArray<T>
General N-dimensional arrays holding real values. The aim of this package to create an general framework to handle multidimensional data. The reference implementation is based on array of floating point or integer, it is, however, super easy to write a wrapper to any array- or collection-implementation making it possible to combine the convenience of this interface with the advantages of the selected collection.
-
-
Method Summary
All Methods Instance Methods Default Methods Modifier and Type Method Description default 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(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(Object... addends)
Updates this NDArray with the element-wise sum of this NDArray and the ones given as parameters.default 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.default NDArray<T>
copyFrom(byte[] array)
Updates this NDArray with the elements of the array given as parameter.default NDArray<T>
copyFrom(double[] array)
Updates this NDArray with the elements of the array given as parameter.default NDArray<T>
copyFrom(float[] array)
Updates this NDArray with the elements of the array given as parameter.default NDArray<T>
copyFrom(int[] array)
Updates this NDArray with the elements of the array given as parameter.default NDArray<T>
copyFrom(long[] array)
Updates this NDArray with the elements of the array given as parameter.default NDArray<T>
copyFrom(short[] array)
Updates this NDArray with the elements of the array given as parameter.default NDArray<T>
copyFrom(Object[] array)
Updates this NDArray with the elements of the array given as parameter.default NDArray<T>
divide(Object... divisor)
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(Object... divisor)
Updates the elements this NDArray with the result of the element-wise division of this NDArray by the parameter NDArrays and scalars.default NDArray<T>
dropDims(int... selectedDims)
Returns a view that references this NDArray as parent, and skips all singleton dimensions included in the parameter list.default NDArray<T>
fill(double value)
Fill this NDArray with the specified valuedefault NDArray<T>
fill(T value)
Fill this NDArray with the specified valuedefault NDArray<T>
inverseMask(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 inverseMask.default 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.default 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.default 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.default 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.default 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.default 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.default 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(Object... multiplicand)
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(Object... multiplicand)
Updates the elements of this NDArray with the element-wise product of this NDArray and the parameter NDArrays and scalars.default NDArray<T>
permuteDims(int... permutation)
Returns a view that references this NDArray as parent, but the order of dimensions are swiched in this view.default NDArray<T>
prod(int... selectedDims)
Returns the product of all elements along the specified dimensions in this NDArray.default NDArray<T>
reshape(int... newShape)
Returns a view that references this NDArray as parent but has a different shape.default 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.default 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.default NDArray<T>
squeeze()
Returns a view that references this NDArray as parent, and skips all singleton dimensions.default NDArray<T>
subtract(Object... substrahends)
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(Object... substrahends)
Updates the elements this NDArray with the result of the element-wise subtraction the parameter NDArrays and scalars from this NDArray.default NDArray<T>
sum(int... selectedDims)
Returns the sum of all elements along the specified dimensions in this NDArray.-
Methods inherited from interface io.github.hakkelt.ndarrays.NDArray
accumulate, add, add, add, add, add, add, add, addInplace, addInplace, addInplace, addInplace, addInplace, addInplace, addInplace, apply, applyOnSlices, applyWithCartesianIndices, applyWithLinearIndices, contains, contentToString, contentToString, copy, copyFrom, dataTypeAsString, divide, divide, divide, divide, divide, divide, divide, divideInplace, divideInplace, divideInplace, divideInplace, divideInplace, divideInplace, divideInplace, dtype, equals, fillUsingCartesianIndices, fillUsingLinearIndices, forEach, forEachWithCartesianIndices, forEachWithLinearIndices, get, get, getNamePrefix, hashCode, iterator, length, mapOnSlices, multiply, multiply, multiply, multiply, multiply, multiply, multiply, multiplyInplace, multiplyInplace, multiplyInplace, multiplyInplace, multiplyInplace, multiplyInplace, multiplyInplace, ndim, norm, norm, norm, parallelStream, prod, reduceSlices, set, set, set, set, shape, shape, similar, spliterator, stream, streamCartesianIndices, streamLinearIndices, subtract, subtract, subtract, subtract, subtract, subtract, subtract, subtractInplace, subtractInplace, subtractInplace, subtractInplace, subtractInplace, subtractInplace, subtractInplace, sum, toArray, toArray, toArray, toString, writeToFile
-
-
-
-
Method Detail
-
sum
default NDArray<T> sum(int... selectedDims)
Description copied from interface:NDArray
Returns the sum of all elements along the specified dimensions in this NDArray.For example, if
A
is a [5 × 8 × 3] array, thenB = A.sum(2)
returns a [5 × 8] array, andB.get(1,1) == A.get(1,1,0) + A.get(1,1,1) + A.get(1,1,2)
.
-
prod
default NDArray<T> prod(int... selectedDims)
Description copied from interface:NDArray
Returns the product of all elements along the specified dimensions in this NDArray.For example, if
A
is a [5 × 8 × 3] array, thenB = A.prod(2)
returns a [5 × 8] array, andB.get(1,1) == A.get(1,1,0) * A.get(1,1,1) * A.get(1,1,2)
.
-
accumulate
default NDArray<T> accumulate(BinaryOperator<T> func, int... selectedDims)
Description copied from interface:NDArray
Returns the accumulation of all elements along the specified dimensions in this NDArray.For example, if
A
is a [5 × 8 × 3] array, thenB = A.accumulate(func, 2)
returns a [5 × 8] array, andB.get(1,1) == func(func(A.get(1,1,0), A.get(1,1,1)), A.get(1,1,2))
.- Specified by:
accumulate
in interfaceNDArray<T extends Number>
- Parameters:
func
- accumulation function that accepts two elements and returns accumulation resultselectedDims
- dimensions along which the accumulation should be performed- Returns:
- result of accumulation of all elements along the specified dimensions
-
add
default NDArray<T> add(Object... addends)
Description copied from interface:NDArray
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.
-
addInplace
default NDArray<T> addInplace(Object... addends)
Description copied from interface:NDArray
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.
- Specified by:
addInplace
in interfaceNDArray<T extends Number>
- Parameters:
addends
- NDArrays and scalars to be added to this NDArray- Returns:
- this NDArray after addition
-
subtract
default NDArray<T> subtract(Object... substrahends)
Description copied from interface:NDArray
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.
-
subtractInplace
default NDArray<T> subtractInplace(Object... substrahends)
Description copied from interface:NDArray
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.
- Specified by:
subtractInplace
in interfaceNDArray<T extends Number>
- Parameters:
substrahends
- NDArrays and scalars to be substracted from this NDArray- Returns:
- this NDArray after substraction
-
multiply
default NDArray<T> multiply(Object... multiplicand)
Description copied from interface:NDArray
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.
-
multiplyInplace
default NDArray<T> multiplyInplace(Object... multiplicand)
Description copied from interface:NDArray
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.
- Specified by:
multiplyInplace
in interfaceNDArray<T extends Number>
- Parameters:
multiplicand
- NDArrays and scalars to be multiplied with this NDArray- Returns:
- this NDArray after multiplication
-
divide
default NDArray<T> divide(Object... divisor)
Description copied from interface:NDArray
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.
-
divideInplace
default NDArray<T> divideInplace(Object... divisor)
Description copied from interface:NDArray
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.
- Specified by:
divideInplace
in interfaceNDArray<T extends Number>
- Parameters:
divisor
- divisors of this NDArray- Returns:
- this NDArray after division
-
fill
default NDArray<T> fill(double value)
Description copied from interface:NDArray
Fill this NDArray with the specified value
-
fill
default NDArray<T> fill(T value)
Description copied from interface:NDArray
Fill this NDArray with the specified value
-
slice
default NDArray<T> slice(Object... slicingExpressions)
Description copied from interface:NDArray
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, thenB = A.slice(1, "2:5", ":")
returns a [3 × 3] array, andB.get(1,1) == A.get(1,3,1)
.
-
mask
default NDArray<T> mask(NDArray<?> mask)
Description copied from interface:NDArray
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.
-
mask
default NDArray<T> mask(Predicate<T> func)
Description copied from interface:NDArray
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.
-
maskWithLinearIndices
default NDArray<T> maskWithLinearIndices(BiPredicate<T,Integer> func)
Description copied from interface:NDArray
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.- Specified by:
maskWithLinearIndices
in interfaceNDArray<T extends Number>
- 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
default NDArray<T> maskWithCartesianIndices(BiPredicate<T,int[]> func)
Description copied from interface:NDArray
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.- Specified by:
maskWithCartesianIndices
in interfaceNDArray<T extends Number>
- 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
-
inverseMask
default NDArray<T> inverseMask(NDArray<?> mask)
Description copied from interface:NDArray
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.- Specified by:
inverseMask
in interfaceNDArray<T extends Number>
- 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 inverseMask
-
permuteDims
default NDArray<T> permuteDims(int... permutation)
Description copied from interface:NDArray
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, thenB = A.permuteDims(1, 0, 2)
returns a [8 × 5 × 3] array, andB.get(3,1,0) == A.get(1,3,0)
.- Specified by:
permuteDims
in interfaceNDArray<T extends Number>
- 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.
-
reshape
default NDArray<T> reshape(int... newShape)
Description copied from interface:NDArray
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, thenB = A.reshape(40, 3)
returns a [40 × 3] array, andB.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.
-
concatenate
default NDArray<T> concatenate(int axis, NDArray<?>... arrays)
Description copied from interface:NDArray
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.- Specified by:
concatenate
in interfaceNDArray<T extends Number>
- 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.
-
selectDims
default NDArray<T> selectDims(int... selectedDims)
Description copied from interface:NDArray
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.
- Specified by:
selectDims
in interfaceNDArray<T extends Number>
- 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
default NDArray<T> dropDims(int... selectedDims)
Description copied from interface:NDArray
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.
-
squeeze
default NDArray<T> squeeze()
Description copied from interface:NDArray
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.
-
copyFrom
default NDArray<T> copyFrom(float[] array)
Description copied from interface:NDArray
Updates this NDArray with the elements of the array given as parameter.Note: the parameter array must have the same shape and this NDArray!
-
copyFrom
default NDArray<T> copyFrom(double[] array)
Description copied from interface:NDArray
Updates this NDArray with the elements of the array given as parameter.Note: the parameter array must have the same shape and this NDArray!
-
copyFrom
default NDArray<T> copyFrom(byte[] array)
Description copied from interface:NDArray
Updates this NDArray with the elements of the array given as parameter.Note: the parameter array must have the same shape and this NDArray!
-
copyFrom
default NDArray<T> copyFrom(short[] array)
Description copied from interface:NDArray
Updates this NDArray with the elements of the array given as parameter.Note: the parameter array must have the same shape and this NDArray!
-
copyFrom
default NDArray<T> copyFrom(int[] array)
Description copied from interface:NDArray
Updates this NDArray with the elements of the array given as parameter.Note: the parameter array must have the same shape and this NDArray!
-
copyFrom
default NDArray<T> copyFrom(long[] array)
Description copied from interface:NDArray
Updates this NDArray with the elements of the array given as parameter.Note: the parameter array must have the same shape and this NDArray!
-
copyFrom
default NDArray<T> copyFrom(Object[] array)
Description copied from interface:NDArray
Updates this NDArray with the elements of the array given as parameter.Note: the parameter array must have the same shape and this NDArray!
-
map
default NDArray<T> map(UnaryOperator<T> func)
Description copied from interface:NDArray
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!
-
mapWithLinearIndices
default NDArray<T> mapWithLinearIndices(BiFunction<T,Integer,T> func)
Description copied from interface:NDArray
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!- Specified by:
mapWithLinearIndices
in interfaceNDArray<T extends Number>
- 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
default NDArray<T> mapWithCartesianIndices(BiFunction<T,int[],T> func)
Description copied from interface:NDArray
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!- Specified by:
mapWithCartesianIndices
in interfaceNDArray<T extends Number>
- 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
-
-