Open-source project
rust-ndarray/ndarray avatar
rust-ndarray/ndarray

ndarray: strided n-dimensional arrays and the cost of a view

ndarray: an N-dimensional array with array views, multidimensional slicing, and efficient operations

4,348 stars394 forksRustApache-2.0

At a glance

What is it?
ndarray gives Rust an n-dimensional array with cheap views, arbitrary-step slicing and matrix multiplication through matrixmultiply or optional BLAS. It suits numeric code that already accepts the crate's stride and lifetime model, and it costs you when your data does not fit that model.
Who is it for?
Adopt ndarray when your Rust code does numeric work on rectangular or strided data and you are prepared to live with its view and lifetime API. Do not adopt it for small fixed-shape records, for a linear buffer where a Vec already does the job, or for a codebase that needs stable APIs across major versions, since the project states that breaking changes are expected between versions.
Can I use it commercially?
Yes. Apache-2.0 is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository last received commits 27 days ago.
What is it written in?
Mainly Rust, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on November 23, 2026, and from our analysis. They are not legal advice.

From daily snapshots

Star history

  • rust-ndarray/ndarray4,348 ★ · +25
Star history
Repository2026-09-232026-11-23
rust-ndarray/ndarray4.3k4.3k

25 Stars in the last 61 days, measured from the daily GitHub snapshot. Compare with other projects

Editorial analysis

An array is a pointer into strided memory, not a nested vector

The core of ndarray is a strided buffer plus a shape and a set of strides, not a tree of vectors. That decision is what makes slicing cheap and what makes some operations awkward. A subview borrows the parent allocation and carries its own shape and stride offsets, so creating one does not copy elements. The cost lands later, at the point where a view must outlive the expression that produced it or where the compiler has to prove the base array is not mutated while a view exists.

Code that assumes a nested structure will not port directly. You address an element through axis indexing, and negative indices count from the end of an axis, which the README calls out as one of its highlights. Iteration is separate again: the crate offers iterators that yield subviews rather than scalars, so a loop written the obvious way can turn into row-by-row subview creation and quietly change what you thought was a flat scan.

Views are cheap to create and hard to keep

Because ArrayView borrows, the lifetime rules become the part of the API you will actually fight. A view of a temporary cannot escape the statement that made it, and stacking operations means threading lifetimes through function signatures.

The payoff when it does work is real. Owned arrays and views share the same indexing and arithmetic surface, so a function can accept ArrayView2<f64> and work for both a freshly computed matrix and a column extracted from a larger one, with no conversion. The README is blunt about the tradeoff on performance: prefer higher order methods and arithmetic operations on arrays first, then iteration, and indexed algorithms last. That ordering is advice about how the views get consumed, not just about style.

matrixmultiply by default, BLAS only when you wire three crates yourself

Matrix multiplication works out of the box. ndarray depends on the matrixmultiply crate for f32 and f64 products, and the README states it is always enabled as a fallback because it supports matrices of arbitrary strides in both dimensions. So the default build handles matrices of arbitrary strides.

Turning on the blas feature moves the responsibility to your Cargo.toml. You pick a provider through blas-src and the backend crate, and the README insists only end-user projects select a provider, since libraries should leave that choice to the binary at the top. The backend version must be the one blas-src itself depends on, and your program must link blas_src explicitly by using it or declaring it.

An example configuration using system openblas:

toml
[dependencies]
ndarray = { version = "0.x.y", features = ["blas"] }
blas-src = { version = "0.10", features = ["openblas"] }
openblas-src = { version = "0.10", features = ["cblas", "system"] }

The system variant avoids compiling the library. A compiled netlib alternative exists for machines without a system BLAS:

toml
[dependencies]
ndarray = { version = "0.x.y", features = ["blas"] }
blas-src = { version = "0.10.0", default-features = false, features = ["netlib"] }

With either configuration, the README says your program must also link to blas_src by using it or explicitly including it:

rust
extern crate blas_src;

A close reading of the version table catches the real upgrade cost

The README states that for ndarray 0.15 or later there is no tight coupling to the blas-src version, so version selection is more flexible. Read the version table it prints next and the flexibility has a boundary. It pairs ndarray 0.16 with blas-src 0.10 and openblas-src 0.10, while 0.15 appears twice, once against blas-src 0.8 and once against 0.7, with openblas-src dropping from 0.10 to 0.9. Those rows are described as versions verified to work together. There is a second mismatch in the same document. The README carries a section titled BLAS on MSRV explaining that ndarray's own minimum is separate from the provider's. An older toolchain that satisfies ndarray can still fail once a BLAS backend is in the graph.

Feature flags decide what compiles, and std decides what exists

Adding the crate is one command, run from your project folder:

bash
cargo add ndarray

Everything else is decided in Cargo.toml. Default is std only. Turning std off changes the API surface rather than just the linking: geomspace, linspace, logspace, range, std, var, var_axis and std_axis are listed as available only when std is on, so a no_std port loses the range and axis-variance constructors outright.

toml
[dependencies]
ndarray = { version = "0.x.y", default-features = false }

The other flags are narrow. serde pulls in serialization support for serde 1.x, rayon enables parallel iterators and par_azip! and turns std back on, approx wires in traits from the approx crate, matrixmultiply-threading turns on threading inside the matrixmultiply package, and portable-atomic-critical-section decides whether portable-atomic uses critical-section. Most of them add a dependency you then own.

Breaking changes are stated policy, not an accident

The Status and Lookout section is unusually direct: still iterating on and evolving the crate, continuously developing, breaking changes expected during evolution from version to version, and the newest stable Rust features adopted where needed. The repository is not archived, and the last push was on 2026-10-27.

That combination means active work and no stability promise. Licensing is not the friction here, since the project is dual-licensed under Apache-2.0 or MIT at your option. The upgrade friction is in the type signatures that your own public API exposes.

The repository layout also tells you what sits on top: crates/ for the subcrates, ndarray-rand/ for random generation, examples/ with axis_ops.rs, zip_many.rs and a sort-axis.rs among them, benches/ for benchmarks, and a change log file at the repository root.

Where nalgebra draws a different line

nalgebra is the comparison people bring to ndarray in Rust, and the two disagree on what an array is. ndarray is built around strided views over a shared buffer, so slicing produces a borrowed view and non-contiguous matrices are a first-class case for its own matrixmultiply fallback. nalgebra organizes around fixed-size and dynamically sized vector and matrix types, which reads more naturally when your algebra is small, size is known at compile time, or you want typed operations without managing strides.

The practical test is your data shape. Data arriving as rows in a file, results of a chain of transformations, or anything you want to slice along an axis mid-computation fits ndarray's model. Data that is fundamentally a point, a transform, or a fixed small matrix fits nalgebra's. Pick against the shape of your data and the operations you repeat, not against a benchmark number neither project prints.

Editorial conclusion

Adopt ndarray when your Rust code does numeric work on rectangular or strided data and you are prepared to live with its view and lifetime API. Do not adopt it for small fixed-shape records, for a linear buffer where a Vec already does the job, or for a codebase that needs stable APIs across major versions, since the project states that breaking changes are expected between versions. Verify first that your performance-critical loops can be written as higher-order methods or arithmetic on whole arrays, and that your BLAS provider matches the blas-src and backend versions listed in the README table before you commit to the blas feature.

Frequently asked questions

What is the meaning of ndarray?

ndarray is a Rust crate. The crate describes itself as an n-dimensional container for general elements and for numerics, with array views, multidimensional slicing and efficient operations.

How do I use ndarray in a Rust project?

Run cargo add ndarray from your project folder to add the latest version. Optional behavior is then selected through feature flags in Cargo.toml, such as std, serde, rayon, approx or blas.

How do I access elements in an ndarray array?

Indexing works through axes, and negative indices refer to elements from the end of an axis. The repository also ships examples/axis_ops.rs, which shows axis indexing and related operations.

What is the difference between ndarray and nalgebra in Rust?

ndarray centers on strided views over a shared buffer, so slicing is cheap and non-contiguous matrices are supported by its own matrixmultiply fallback. nalgebra organizes around vector and matrix types for geometric and linear algebra work, which suits fixed small shapes over arbitrary strides.

Should I use ndarray instead of a Vec for numeric data?

Use ndarray when you need more than one axis, slicing with step sizes, or matrix multiplication, since a Vec carries a single dimension and no shape or stride information. The README advises preferring higher order methods and arithmetic on whole arrays over iteration and indexed algorithms.

Official sources

  1. License: Apache-2.0
  2. Project website
  3. README
  4. Releases
  5. rust-ndarray/ndarray on GitHub
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/rust-ndarray-ndarray.svg)](https://hysenlabs.com/projects/rust-ndarray-ndarray)

Star history chart for your README

markdown
[![Star history](https://hysenlabs.com/chart/rust-ndarray-ndarray.svg)](https://hysenlabs.com/projects/rust-ndarray-ndarray)

Was this useful?