Monkey
Monkey

Reputation: 1866

Java equivalent for the Numpy multi-dimensional object

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

Upvotes: 30

Views: 56118

Answers (10)

KIC
KIC

Reputation: 6081

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.

Upvotes: 20

duffymo
duffymo

Reputation: 309008

I'd recommend la4j, an elegant, modern linear algebra library, or JBLAS, another that ports BLAS to Java.

Upvotes: 1

qwerty
qwerty

Reputation: 830

This is an old question, but I just thought I'd add these two Java ndarray libraries:

Upvotes: 2

iirekm
iirekm

Reputation: 9446

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.

Upvotes: 1

Asim Jalis
Asim Jalis

Reputation: 904

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.

Upvotes: 1

Aleksandr Dubinsky
Aleksandr Dubinsky

Reputation: 23535

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

Upvotes: 2

mikera
mikera

Reputation: 106401

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:

  • Arbitrary N-dimensional arrays of numeric values (in this case, Java doubles)
  • Lightweight views using strided access for efficient slicing
  • A broad range of mathematical operations with effiecient implementations

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

Upvotes: 13

Monkey
Monkey

Reputation: 1866

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.

Upvotes: 2

user983716
user983716

Reputation: 2082

I would say that java has nothing 'like' numpy. numpy is a large mathematical oriented project which does not really fit in java mentality.

It does not meen that there is no good collection libraries in java! Guava has the Table interface with two good implementations, ArrayTable and HashBasedTable. It's more a collection library that a mathematical tool but it's very useful.

For speed and memory efficiency, threre is trove. A collection library that works with primitives.

For maticies operations, JAMA seems good.

As far as I know, you will need to code more and to use more library in java than python.

Upvotes: -4

duffymo
duffymo

Reputation: 309008

You can use numerical libraries for linear algebra; those will have matricies in them. Have a look at Apache Commons Math.

Upvotes: 4

Related Questions