General framework for multi-dimensional arrays holding either complex, floating point and integer values.
- Provide an easy way to create minimal wrappers for n-dimensinal array implementations,
- Give a rich interface to query and modify data, and
- Allow effortless conversion between wrapped data structures.
- Can be parametrized with Float, Double, Byte, Short, Integer, Long, BigInteger, BigDecimal, and Complex from org.apache.commons.math3 package
- Easy initialization: copying data from (multi-dimensional) arrays of primitive values or NDArrays of any kind, and also filling with a scalar value
- Lightweight views: slice (select a specific slice or range of slices along arbitrary dimension), permuteDims (change order of indexing), reshape (change shape of data)
- Basic linear algebra operations: add, subtract, multiply, and divide an NDArray with scalar or another NDArray (element-wise)
- Implements streaming and iterations of values or indices
- Implemented fully in native Java
ComplexNDArray<Double> array = new ComplexDoubleNDArray(4, 5, 3)
.fillUsingLinearIndices(i -> new Complex(Math.random(), Math.random()));
array.slice("2:3", ":", 1).fill(2); // updates the selected range in the original array
ComplexNDArray<Double> sum = array.sum(2); // Calculates sum along axis 2, producing a 4 x 5 NDarray
// Euclidean norm of element-wise product of two slices:
array.slice("0:2", ":", 1).multiply(array.slice("2:4", ":", 1)).norm();
// Assign zero to elements where the first coordinate is an even number:
array.streamCartesianIndices()
.filter(idx -> idx[0] % 2 == 0)
.forEach(idx -> array.set(0, idx));
// Alternative solution:
array.applyWithCartesianIndices((value, idx) -> idx[0] % 2 == 0 ? 0 : value);
array.addInplace(new Complex(1, 3.5)); // Adds 1 + 3.5i to all elements
-
It presents NDArray features through examples, and illustrates how the task would be solved in Matlab, Python and Julia: Tutorial
-
For more examples, see tests in src/test/java/com/github/hakkelt/ndarrays/basic.
-
For a complete list of features, please refer to the javadoc documentation.
<dependencies>
<dependency>
<groupId>io.github.hakkelt</groupId>
<artifactId>ndarrays</artifactId>
<version>2.2.0</version>
</dependency>
...
</dependencies>
Download jar files from latest release, and add their path to java path. You should also take care of the dependencies (org.apache.commons.commons-math3
, org.apache.commons.commons-lang3
).
- Python's numpy.ndarray
- Julia's native multidimensional array type