Class NumpyArray<Type>
- java.lang.Object
-
- ai.sklearn4j.core.libraries.numpy.NumpyArray<Type>
-
- Type Parameters:
Type- Type of the elements of the array.
public class NumpyArray<Type> extends Object
Provide the functionality of the Numpy arrays and an abstraction over the element types.
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedNumpyArray(INumpyArrayWrapper data)Instantiate a new object of NumpyArray.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static voidaddCounter(int[] counter, int[] shape)The numpy array could be multidimensional.voidapplyToEachElement(INumpyArrayElementOperation<Type> operation)Applies a provided operation on every element of the array and stores it in the same array.voidapplyToEachElementAnsSaveToTarget(NumpyArray target, INumpyArrayElementOperation<Type> operation)Applies a provided operation on every element of the array and stores it in a specified target array.Typeget(int... indices)Gets an element in the array specified by it index.int[]getShape()Gets the shape of the numpy array.TypegetSingleValue()Gets the first element of the numpy array from its memory layout.INumpyArrayWrappergetWrapper()Gets the object that wraps the underlying array.booleanisFloatingPoint()Returns a boolean indicating if the underlying data type is floating numbers or not.booleanisSingleValueArray()Returns a boolean indicating if the array contains only a single element.intnumberOfBytes()Gets the number of bytes allocated in memory for each element.intnumberOfDimensions()Gets the number of dimensions of the numpy array.voidset(Object value, int... indices)Sets an element in the array specified by it index.StringtoString()Returns a string representation of the array for DEBUGGING purposes.NumpyArray<Type>transpose()Transposes an array by reversing the order of its dimensions.NumpyArray<Type>wrapInnerSubsetArray(int... indices)Wraps a subset of the numpy array.
-
-
-
Constructor Detail
-
NumpyArray
protected NumpyArray(INumpyArrayWrapper data)
Instantiate a new object of NumpyArray.- Parameters:
data- The content of the numpy array.
-
-
Method Detail
-
getShape
public int[] getShape()
Gets the shape of the numpy array.- Returns:
- The array shape.
-
get
public Type get(int... indices)
Gets an element in the array specified by it index.- Parameters:
indices- The index of the element to be retrieved.- Returns:
- The element value in the array specified by its index.
-
applyToEachElement
public void applyToEachElement(INumpyArrayElementOperation<Type> operation)
Applies a provided operation on every element of the array and stores it in the same array.- Parameters:
operation- The operation to be applied on the elements.
-
applyToEachElementAnsSaveToTarget
public void applyToEachElementAnsSaveToTarget(NumpyArray target, INumpyArrayElementOperation<Type> operation)
Applies a provided operation on every element of the array and stores it in a specified target array.- Parameters:
target- The array that the result should be stored into.operation- The operation to be applied on the elements.
-
addCounter
public static void addCounter(int[] counter, int[] shape)The numpy array could be multidimensional. To iterate over the element given that the dimension is dynamic, a counter is used. This method increase the value of the counter to move the index to the next element.- Parameters:
counter- The current index.shape- The shape of the array.
-
set
public void set(Object value, int... indices)
Sets an element in the array specified by it index.- Parameters:
value- The value to be set.indices- The index of the element to be modified.
-
isFloatingPoint
public boolean isFloatingPoint()
Returns a boolean indicating if the underlying data type is floating numbers or not.- Returns:
- A boolean indicating if the underlying data type is floating numbers or not.
-
numberOfBytes
public int numberOfBytes()
Gets the number of bytes allocated in memory for each element.- Returns:
- Number of bytes allocated in memory for each element.
-
transpose
public NumpyArray<Type> transpose()
Transposes an array by reversing the order of its dimensions.- Returns:
- The transposed array.
-
isSingleValueArray
public boolean isSingleValueArray()
Returns a boolean indicating if the array contains only a single element.- Returns:
- A boolean indicating if the array contains only a single element.
-
getSingleValue
public Type getSingleValue()
Gets the first element of the numpy array from its memory layout.- Returns:
- The first element of the array.
-
wrapInnerSubsetArray
public NumpyArray<Type> wrapInnerSubsetArray(int... indices)
Wraps a subset of the numpy array. This methods works only when slicing the most inner dimensions of the array. For example, if the shape is [2, 6, 4, 8], wrapInnerSubsetArray(1, 3) is equivalent to numpy array[1, 3, :, :].- Parameters:
indices- The indices of the first dimensions to keep.- Returns:
- A new INumpyArrayWrapper wrapping the inner dimensions. This array has the same reference.
-
numberOfDimensions
public int numberOfDimensions()
Gets the number of dimensions of the numpy array.- Returns:
-
getWrapper
public INumpyArrayWrapper getWrapper()
Gets the object that wraps the underlying array.- Returns:
- The object that wraps the underlying array.
-
-