Expand description
This crate provides Rust interfaces for NumPy C APIs, especially for the ndarray class.
It uses pyo3
for Rust bindings to CPython, and uses
ndarray
as the Rust matrix library.
To resolve its dependency on NumPy, it calls import numpy.core
internally.
This means that this crate should work if you can use NumPy in your Python environment,
e.g. after installing it by pip install numpy
. It does not matter whether you use
the system environment or a dedicated virtual environment.
Loading NumPy is done automatically and on demand. So if it is not installed, the functions provided by this crate will panic instead of returning a result.
Example
use numpy::pyo3::Python;
use numpy::ndarray::array;
use numpy::{ToPyArray, PyArray};
Python::with_gil(|py| {
let py_array = array![[1i64, 2], [3, 4]].to_pyarray(py);
assert_eq!(
py_array.readonly().as_array(),
array![[1i64, 2], [3, 4]]
);
})
Re-exports
pub use ndarray;
pub use pyo3;
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;
Modules
Safe interface for NumPy’s ndarray class
Defines conversion traits between rust types and numpy data types.
Low-Level bindings for NumPy C API.
Wrapper of the array iterator API.
Macros
Return the Einstein summation convention of given tensors.
Structs
Represents that dimensionalities of the given arrays do not match.
Represents that given Vec
cannot be treated as an array.
Represents that the given array is not contiguous.
Binding of numpy.dtype
.
Readonly reference of PyArray
.
Represents that types of the given arrays do not match.
Traits
Represents that a type can be an element of PyArray
.
Iterator mode for single iterator
Functions
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.
Returns the type descriptor (“dtype”) for a registered type.
Return the Einstein summation convention of given tensors.
Return the inner product of two arrays.
Type Definitions
one-dimensional
two-dimensional
three-dimensional
four-dimensional
five-dimensional
six-dimensional
dynamic-dimensional
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.