Class NDArray

java.lang.Object
com.groupe8.ttykm.NDArray

public class NDArray extends Object
A multidimensional array of floats, inspired by NumPy's ndarray. Supports 1D (vector) and 2D (matrix) shapes.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    final int
     
    final int
     
  • Method Summary

    Modifier and Type
    Method
    Description
    add(float scalar)
    Returns a new NDArray equal to this + scalar (element-wise).
    add(NDArray other)
    Returns a new NDArray equal to this + other (element-wise).
    void
    addInPlace(float scalar)
    Adds a scalar to this array in-place (+=).
    void
    Adds other to this array in-place (+=).
    static NDArray
    arange(float stop)
    Creates a 1D NDArray with values in [0, stop).
    static NDArray
    arange(float start, float stop, float step)
    Creates a 1D NDArray with evenly spaced values in [start, stop).
    static NDArray
    arange(int stop)
    Creates a 1D NDArray with values in [0, stop).
    static NDArray
    arange(int start, int stop, int step)
    Creates a 1D NDArray with integer-typed convenience overload.
    static NDArray
    array(float... values)
    Creates a 1D NDArray from the given values.
    static NDArray
    array(float[][] values)
    Creates a 2D NDArray from a row-major 2D float array.
    float
    get(int i)
    Gets an element from a 1D array.
    float
    get(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.
    void
    set(int i, float value)
    Sets an element in a 1D array.
    void
    set(int row, int col, float value)
    Sets an element in a 2D array.
    int[]
    Returns a copy of the shape array.
    Returns a NumPy-style string representation. 1D: [1.0 2.0 3.0] 2D: [[1.0 2.0] [3.0 4.0]]
    static NDArray
    zeros(int... shape)
    Creates an NDArray of zeros with the given shape.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • ndim

      public final int ndim
    • size

      public final int size
  • Method Details

    • array

      public static NDArray array(float... values)
      Creates a 1D NDArray from the given values.
    • array

      public static NDArray array(float[][] values)
      Creates a 2D NDArray from a row-major 2D float array.
    • zeros

      public static NDArray zeros(int... shape)
      Creates an NDArray of zeros with the given shape.
    • arange

      public static NDArray arange(float start, float stop, float step)
      Creates a 1D NDArray with evenly spaced values in [start, stop). Equivalent to numpy.arange(start, stop, step).
    • arange

      public static NDArray arange(float stop)
      Creates a 1D NDArray with values in [0, stop).
    • arange

      public static NDArray arange(int start, int stop, int step)
      Creates a 1D NDArray with integer-typed convenience overload.
    • arange

      public static NDArray arange(int stop)
      Creates a 1D NDArray with values in [0, stop).
    • shape

      public int[] shape()
      Returns a copy of the shape array.
    • reshape

      public NDArray reshape(int... newShape)
      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

      public NDArray add(NDArray other)
      Returns a new NDArray equal to this + other (element-wise). Both arrays must have the same shape.
    • add

      public NDArray add(float scalar)
      Returns a new NDArray equal to this + scalar (element-wise).
    • addInPlace

      public void addInPlace(NDArray other)
      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

      public String toString()
      Returns a NumPy-style string representation. 1D: [1.0 2.0 3.0] 2D: [[1.0 2.0] [3.0 4.0]]
      Overrides:
      toString in class Object