Skip to content

NumPy4J Wiki

Darius Nica edited this page Jul 22, 2026 · 1 revision

Welcome to the NumPy4J wiki!

NumPy4J is an open-source numerical computing library for Java inspired by Python's NumPy. It provides multidimensional arrays (NDArray), broadcasting, array manipulation, and a growing set of linear algebra operations through a simple and familiar API.


Features

NDArray

  • N-dimensional arrays
  • Fast indexing and slicing
  • Broadcasting for element-wise operations
  • Reshaping and flattening
  • Views through transpose
  • Functional mapping over elements

Array Creation

  • zeros()
  • ones()
  • full()
  • empty()
  • random()
  • eye()
  • arange()
  • linspace()
  • array()

Element-wise Operations

  • Addition
  • Subtraction
  • Multiplication
  • Division
  • Power
  • Exponential
  • Functional mapping

Statistics

  • sum()
  • mean()

Shape Manipulation

  • reshape()
  • flatten()
  • ravel()
  • slice()
  • copy()

Linear Algebra

  • Matrix multiplication (matmul)
  • Dot product (dot)
  • Matrix transpose (transpose)
  • Matrix inverse (inv)
  • Determinant (det)
  • Euclidean norm (norm)
  • Linear system solver (solve)
  • Matrix rank (rank)

Installation

Maven

<dependency>
    <groupId>org.numpy4j</groupId>
    <artifactId>numpy4j</artifactId>
    <version>2.0.0</version>
</dependency>

Gradle

implementation "org.numpy4j:numpy4j:2.0.0"

Quick Start

Create an array:

NDArray a = NDArray.of(new double[]{
    1, 2,
    3, 4
}, 2, 2);

Element-wise addition:

NDArray b = NDArray.ones(2, 2);

NDArray c = a.add(b);

Broadcasting:

NDArray matrix = NDArray.of(new double[]{
    1,2,3,
    4,5,6
},2,3);

NDArray vector = NDArray.of(new double[]{
    10,20,30
},3);

NDArray result = matrix.add(vector);

Matrix multiplication:

NDArray C = LinearAlgebra.matmul(A, B);

Solve a linear system:

NDArray A = NDArray.of(new double[]{
    3, 2,
    1, 2
}, 2, 2);

NDArray b = NDArray.of(new double[]{
    5,
    5
}, 2);

NDArray x = LinearAlgebra.solve(A, b);

Compute a determinant:

double det = LinearAlgebra.det(A);

Transpose a matrix:

NDArray T = LinearAlgebra.transpose(A);

Testing

NumPy4J is validated against reference implementations generated with Python's NumPy.

The automated test suite compares Java results with NumPy-generated datasets covering:

  • Broadcasting
  • Matrix multiplication
  • Dot products
  • Reshape
  • Transpose
  • Linear system solving
  • Element-wise arithmetic
  • Power
  • Slicing
  • Aggregate operations

This helps ensure behavior remains consistent with NumPy wherever applicable.


Design Goals

NumPy4J is designed to be:

  • Familiar to NumPy users
  • Lightweight with minimal dependencies
  • Easy to integrate into Java applications
  • Well documented
  • Extensible for future numerical and scientific computing features

Roadmap

Future releases are planned to include additional numerical computing functionality, including:

  • Matrix decompositions (QR, LU, Cholesky)
  • Eigenvalue and eigenvector computation
  • Advanced statistics
  • Additional array manipulation utilities
  • Performance optimizations
  • Expanded NumPy compatibility

Contributing

Contributions are welcome!

You can help by:

  • Reporting bugs
  • Improving documentation
  • Adding unit tests
  • Implementing new NumPy-compatible features
  • Improving performance

Please open an issue or submit a pull request to discuss proposed changes.


License

NumPy4J is released under the MIT License.

Clone this wiki locally