Package com.groupe8.ttykm
Class NDArray
java.lang.Object
com.groupe8.ttykm.NDArray
A multidimensional array of floats, inspired by NumPy's ndarray.
Supports 1D (vector) and 2D (matrix) shapes.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionadd(float scalar) Returns a new NDArray equal to this + scalar (element-wise).Returns a new NDArray equal to this + other (element-wise).voidaddInPlace(float scalar) Adds a scalar to this array in-place (+=).voidaddInPlace(NDArray other) Adds other to this array in-place (+=).static NDArrayarange(float stop) Creates a 1D NDArray with values in [0, stop).static NDArrayarange(float start, float stop, float step) Creates a 1D NDArray with evenly spaced values in [start, stop).static NDArrayarange(int stop) Creates a 1D NDArray with values in [0, stop).static NDArrayarange(int start, int stop, int step) Creates a 1D NDArray with integer-typed convenience overload.static NDArrayarray(float... values) Creates a 1D NDArray from the given values.static NDArrayarray(float[][] values) Creates a 2D NDArray from a row-major 2D float array.floatget(int i) Gets an element from a 1D array.floatget(int row, int col) Gets an element from a 2D array.reshape(int... newShape) Returns a new NDArray with the same data but a different shape.voidset(int i, float value) Sets an element in a 1D array.voidset(int row, int col, float value) Sets an element in a 2D array.int[]shape()Returns a copy of the shape array.toString()Returns a NumPy-style string representation. 1D: [1.0 2.0 3.0] 2D: [[1.0 2.0] [3.0 4.0]]static NDArrayzeros(int... shape) Creates an NDArray of zeros with the given shape.
-
Field Details
-
ndim
public final int ndim -
size
public final int size
-
-
Method Details
-
array
Creates a 1D NDArray from the given values. -
array
Creates a 2D NDArray from a row-major 2D float array. -
zeros
Creates an NDArray of zeros with the given shape. -
arange
Creates a 1D NDArray with evenly spaced values in [start, stop). Equivalent to numpy.arange(start, stop, step). -
arange
Creates a 1D NDArray with values in [0, stop). -
arange
Creates a 1D NDArray with integer-typed convenience overload. -
arange
Creates a 1D NDArray with values in [0, stop). -
shape
public int[] shape()Returns a copy of the shape array. -
reshape
Returns a new NDArray with the same data but a different shape. The total number of elements must remain the same. -
get
public float get(int i) Gets an element from a 1D array. -
get
public float get(int row, int col) Gets an element from a 2D array. -
set
public void set(int i, float value) Sets an element in a 1D array. -
set
public void set(int row, int col, float value) Sets an element in a 2D array. -
add
Returns a new NDArray equal to this + other (element-wise). Both arrays must have the same shape. -
add
Returns a new NDArray equal to this + scalar (element-wise). -
addInPlace
Adds other to this array in-place (+=). Both arrays must have the same shape. -
addInPlace
public void addInPlace(float scalar) Adds a scalar to this array in-place (+=). -
toString
Returns a NumPy-style string representation. 1D: [1.0 2.0 3.0] 2D: [[1.0 2.0] [3.0 4.0]]
-