public class NDArray<T extends AbstractNumber = Double>:
Represents a multi-dimensional array (NDArray) with elements of type T.
Storage model:
NDArray<Double> uses a native contiguous buffer for hot numeric kernels@param <T> The numeric element type.
import klyn.math values = NDArray<Double>.fromList([1.0, 4.0, 9.0]) print(values.sqrt())
| Modifier and Type | Member | Description |
|---|---|---|
| public readonly property | ndimndim as UInt: |
The number of dimensions in the array. |
| public readonly property | shape | The shape of the array. |
| public readonly property | sizesize as UInt: |
The total number of elements in the array. |
| public readonly proper | tty t as NDArray<T>: |
The transpose of the NDArray (2D only). |
| Modifier and Type | Member | Description |
|---|---|---|
| public | NDArray | Constructs a new NDArray with the given shape. |
| public | NDArray | Constructs a new NDArray from a read-only shape. |
| public | NDArray | Constructs a new NDArray from a tuple shape. |
| public | NDArray | Constructs a new 1D NDArray with the given size. |
| Modifier and Type | Member | Description |
|---|---|---|
| public native | absabs() as NDArray<T> |
Returns the element-wise absolute value. |
| public native | acos | Returns the element-wise arccosine. |
| public native | asin | Returns the element-wise arcsine. |
| public native | atan | Returns the element-wise arctangent. |
| public | atan2 | Returns the element-wise `atan2(this, value)`. |
| public native | atan2 | Returns the element-wise `atan2(this, other)`. |
| public native | cbrt | Returns the element-wise cube root. |
| public native | ceilceil() as NDArray<T> |
Applies `ceil` element-wise while preserving the array element type. |
| public native | cos | Returns the element-wise cosine in radians. |
| public native | cosh | Returns the element-wise hyperbolic cosine. |
| public native | degrees | Converts each element from radians to degrees. |
| public native | exp | Returns the element-wise exponential. |
| public native | exp2 | Returns the element-wise power of two. |
| public native | expm1 | Returns the element-wise `exp(value) - 1`. |
| public static | eye | Creates a new NDArray with ones on the diagonal and zeros elsewhere. |
| public | flattenflatten() as NDArray<T>: |
Flattens the NDArray into a 1D array. |
| public native | floorfloor() as NDArray<T> |
Applies `floor` element-wise while preserving the array element type. |
| public | fmod | Returns the element-wise floating-point remainder with a scalar. |
| public native | fmod | Returns the element-wise floating-point remainder with another array. |
| public static | fromList | Creates a 2D NDArray from a nested list. |
| public static | fromList | Creates a 1D NDArray from a list. |
| public static | full | Creates a new NDArray filled with a given value. |
| public static | full | Creates a new NDArray filled with a given value. |
| public static | full | Creates a new NDArray filled with a given value. |
| public static | full | Creates a new NDArray filled with a given value using a tuple shape. |
| public | hypot | Returns the element-wise Euclidean distance with a scalar. |
| public native | hypot | Returns the element-wise Euclidean distance with another array. |
| public native | log | Returns the element-wise natural logarithm. |
| public native | log10 | Returns the element-wise base-10 logarithm. |
| public native | log1p | Returns the element-wise `log(1 + value)`. |
| public native | log2 | Returns the element-wise base-2 logarithm. |
| public | maxmax() as Object: |
Returns the maximum value of the array. |
| public | minmin() as Object: |
Returns the minimum value of the array. |
| public static | ones | Creates a new NDArray with ones. |
| public static | ones | Creates a new NDArray with ones. |
| public static | ones | Creates a new NDArray with ones. |
| public static | ones | Creates a new NDArray with ones from a tuple shape. |
| public native | pow | Raises each element to the matching power array. |
| public | pow | Raises each element to the given scalar power. |
| public native | radians | Converts each element from degrees to radians. |
| public static | randint | Creates a NDArray with random integers in `[min, max]` using read-only shape dimensions. |
| public static | randint | Creates a new NDArray with random integers. |
| public static | randint | Creates a NDArray with random integers in `[min, max]` using a tuple shape. |
| public static | randint | Creates a 1D NDArray with random integers in `[min, max]`. |
| public static | randn | Creates a NDArray sampled from a normal-like distribution using read-only shape dimensions. |
| public static | randn | Creates a new NDArray with random floating-point numbers from a normal distribution. |
| public static | randn | Creates a NDArray sampled from a normal-like distribution using a tuple shape. |
| public static | randn | Creates a 1D NDArray sampled from a normal-like distribution. |
| public static | random | Creates a NDArray with random values in `[0, 1)` using read-only shape dimensions. |
| public static | random | Creates a new NDArray with random values in [0, 1). |
| public static | random | Creates a NDArray with random values in `[0, 1)` using a tuple shape. |
| public static | random | Creates a 1D NDArray with random values in `[0, 1)`. |
| public | reshape | Reshapes the NDArray using two dimensions. |
| public | reshape | Reshapes the NDArray to the specified shape. |
| public | reshape | Reshapes the NDArray using a tuple shape. |
| public native | roundround() as NDArray<T> |
Rounds each element to the nearest integer value while preserving the array element type. |
| public | setset(i as Int, value as T) as Void: |
Sets one element in a 1D NDArray. |
| public | set | Sets one element in a 2D NDArray. |
| public native | sin | Returns the element-wise sine in radians. |
| public native | sinh | Returns the element-wise hyperbolic sine. |
| public | sortsort() as NDArray<T>: |
Sorts the NDArray in place. |
| public | sort | Sorts the NDArray along one axis, in place. |
| public native | sqrt | Returns the element-wise square root. |
| public native | sumsum() as Object |
Computes the sum of all elements. |
| public | sum | Computes the sum along one axis. |
| public native | tan | Returns the element-wise tangent in radians. |
| public native | tanh | Returns the element-wise hyperbolic tangent. |
| public | toStringtoString() as String: |
Returns a string representation of the array. |
| public native | trunctrunc() as NDArray<T> |
Applies `trunc` element-wise while preserving the array element type. |
| public static | zeros | Creates a new NDArray with zeros. |
| public static | zeros | Creates a new NDArray with zeros. |
| public static | zeros | Creates a new NDArray with zeros. |
| public static | zeros | Creates a new NDArray with zeros from a tuple shape. |