Crate numpy[][src]

Expand description

rust-numpy provides Rust interfaces for NumPy C APIs, especially for ndarray class.

It uses pyo3 for rust bindings to cpython, and uses ndarray for rust side matrix library.

For numpy dependency, it calls import numpy.core internally. So you just need numpy installed by pip install numpy or other ways in your python environment. You can use both system environment and virtualenv.

This library loads numpy module automatically. So if numpy is not installed, it simply panics, instead of returing a result.


extern crate ndarray;
use numpy::{ToPyArray, PyArray};
fn main() {
    pyo3::Python::with_gil(|py| {
        let py_array = array![[1i64, 2], [3, 4]].to_pyarray(py);
            array![[1i64, 2], [3, 4]]


pub use ndarray;
pub use crate::array::get_array_module;
pub use crate::array::PyArray;
pub use crate::array::PyArray0;
pub use crate::array::PyArray1;
pub use crate::array::PyArray2;
pub use crate::array::PyArray3;
pub use crate::array::PyArray4;
pub use crate::array::PyArray5;
pub use crate::array::PyArray6;
pub use crate::array::PyArrayDyn;
pub use crate::convert::IntoPyArray;
pub use crate::convert::NpyIndex;
pub use crate::convert::ToNpyDims;
pub use crate::convert::ToPyArray;
pub use crate::npyffi::PY_ARRAY_API;
pub use crate::npyffi::PY_UFUNC_API;
pub use crate::npyiter::NpyIterFlag;
pub use crate::npyiter::NpyMultiIter;
pub use crate::npyiter::NpyMultiIterBuilder;
pub use crate::npyiter::NpySingleIter;
pub use crate::npyiter::NpySingleIterBuilder;


Safe interface for NumPy ndarray

Defines conversion traits between rust types and numpy data types.

Low-Level bindings for NumPy C API.


Create an Array with one, two or three dimensions.

Return the Einstein summation convention of given tensors.

Create a PyArray with one, two or three dimensions. This macro is backed by ndarray::array.


Represents that given vec cannot be treated as array.

Represents that the array is not contiguous.

Readonly reference of PyArray.

Represents that shapes of the given arrays don’t match.


Represents numpy data type.


Represents that a type can be an element of PyArray.

Iterator mode for single iterator


Create a one-dimensional index

Create a two-dimensional index

Create a three-dimensional index

Create a four-dimensional index

Create a five-dimensional index

Create a six-dimensional index

Create a dynamic-dimensional index

Return the dot product of two arrays.

Return the Einstein summation convention of given tensors.

Return the inner product of two arrays.

Type Definitions








One-dimensional readonly array.

Two-dimensional readonly array.

Three-dimensional readonly array.

Four-dimensional readonly array.

Five-dimensional readonly array.

Six-dimensional readonly array.

Dynamic-dimensional readonly array.