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. Libraries like Colt and Parallel Colt use or have dependencies with GPL in the license, making them unsuitable for commercial use. ND4J and ND4S are used by national laboratories such as Nasa JPL 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.

Main Features

  • Versatile n-dimensional array object
  • Multiplatform functionality including GPUs
  • Linear algebra and signal processing functions

ND4J/ND4S Specifics

  • Supports GPUs via CUDA
  • Integrates with Hadoop and Spark
  • ND4S’s API mimics the semantics of Numpy

Code Examples

If you have any questions, please contact us on Gitter.

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:

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

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.