After using it for a while, I really like the Numpy multi-dimensional array. It's helpful to write algorithms with a concise yet readable and fairly general code. I wish to have the same thing in Java. Before coding a multi-dimensional array with a Numpy-like API myself, is there such a thing already ?
[PS] I searched a bit, did not see
Therefore the equivalent for NumPy in Java would simply be the standard Java math module.
No, Java does not support multi-dimensional arrays. Java supports arrays of arrays. In Java, a two-dimensional array is nothing but, an array of one-dimensional arrays.
In Java, a multi-dimensional array is nothing but an array of arrays. 2D array − A two-dimensional array in Java is represented as an array of one-dimensional arrays of the same type. Mostly, it is used to represent a table of values with rows and columns − Int[][] myArray = {{10, 20, 30}, {11, 21, 31}, {12, 22, 32} }
In this article, we will show how to declare and initialize Multi Dimensional Array in Java. For Java Multi Dimensional Array better understanding, we are using Three Dimensional Array. Moreover, you can try four dimensional array using the same technique.
The OP is from 2011. So as of end of 2015 I would like mention that there is a new kid in town which claims to be numpy for java -> nd4j. The nice thing is that nd4j is an abstraction layer on top of different libraries like blas. Depending on the size of your matrices there are underlying implementations twice as fast as numpy or jblas. And your code is real platform independent.
The library Vectorz (https://github.com/mikera/vectorz) offers a fully featured NDArray that is broadly equivalent in functionality to Numpy's NDArray, i.e. it offers the fullowing features:
It's also very fast: it is much faster then NumPy for most operations, although NumPy may still be faster for certain large matrix operations because it uses the native BLAS libraries to accelerate these.
Here's the NDArray class itself:
https://github.com/mikera/vectorz/blob/develop/src/main/java/mikera/arrayz/NDArray.java
Disclaimer: I'm the author of Vectorz
You can use numerical libraries for linear algebra; those will have matricies in them. Have a look at Apache Commons Math.
So the closest match seems to be Colt ! http://acs.lbl.gov/software/colt/
It features a multi-dimensional array object, views over an array and your usual linear algebra ! And it's seems to be rather efficient.
Scala has a wider number of numpy-like libraries, if that counts. (You should even be able to use them from Java.)
BIDMat promises to be both powerful and fast (and GPU-powered).
As already mentioned, there is also Breeze
Another great option is to use Spark’s DataFrame API.
http://spark.apache.org/docs/latest/sql-programming-guide.html
This gives you a Pandas/Numpy like interface to arrays in Java. Plus the code is inherently parallelizable and can be run on a cluster of machines if your data size increases.
Java is rather clumsy for nd-arrays (no operator overloading, etc). If Kotlin is OK, you can try Kotlin-NumPy (https://github.com/Kotlin/kotlin-numpy)
nd4j (https://github.com/deeplearning4j/nd4j) was quite popular some time ago, but now it seems not maintained.
This is an old question, but I just thought I'd add these two Java ndarray libraries:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With