Fork me on GitHub

ND4J: N-Dimensional Arrays for Java

ND4J and ND4S are scientific computing libraries for the JVM. They are meant to be used in production environments, which means routines are designed to run fast with minimum RAM requirements.

Main features

A usability gap has separated Java, Scala and Clojure programmers from the most powerful tools in data analysis, like NumPy or Matlab. Libraries like Breeze don’t support n-dimensional arrays, or tensors, which are necessary for deep learning and other tasks. ND4J and ND4S are used by national laboratories for tasks such as climatic modeling, which require computationally intensive simulations.

ND4J brings the intuitive scientific computing tools of the Python community to the JVM in an open source, distributed and GPU-enabled library. In structure, it is similar to SLF4J. ND4J gives engineers in production environments an easy way to port their algorithms and interface with other libraries in the Java and Scala ecosystems.

Click here to get started, or read on.

ND4J/ND4S Specifics

Code Example

Create a 2 x 2 NDarray:

INDArray arr1 = Nd4j.create(new float[]{1,2,3,4},new int[]{2,2});


[[1.0 ,3.0]
[2.0 ,4.0]

Adding a scalar with in-place operations:


Each element is incremented by one:

[[2.0 ,4.0]
[3.0 ,5.0]

Create a second array (arr2) and adding it to the first (arr1):

INDArray arr2 = ND4j.create(new float[]{5,6,7,8},new int[]{2,2});


[[7.0 ,11.0]
[9.0 ,13.0]

You get the idea. Now get started.