-
Notifications
You must be signed in to change notification settings - Fork 0
NumPy4J Wiki
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.
- N-dimensional arrays
- Fast indexing and slicing
- Broadcasting for element-wise operations
- Reshaping and flattening
- Views through transpose
- Functional mapping over elements
zeros()ones()full()empty()random()eye()arange()linspace()array()
- Addition
- Subtraction
- Multiplication
- Division
- Power
- Exponential
- Functional mapping
sum()mean()
reshape()flatten()ravel()slice()copy()
- Matrix multiplication (
matmul) - Dot product (
dot) - Matrix transpose (
transpose) - Matrix inverse (
inv) - Determinant (
det) - Euclidean norm (
norm) - Linear system solver (
solve) - Matrix rank (
rank)
<dependency>
<groupId>org.numpy4j</groupId>
<artifactId>numpy4j</artifactId>
<version>2.0.0</version>
</dependency>implementation "org.numpy4j:numpy4j:2.0.0"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);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.
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
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
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.
NumPy4J is released under the MIT License.