[][src]Crate numpy

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.

Example

#[macro_use]
extern crate ndarray;
use pyo3::prelude::Python;
use numpy::{ToPyArray, PyArray};
fn main() {
    let gil = Python::acquire_gil();
    let py = gil.python();
    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 crate::array::get_array_module;
pub use crate::array::PyArray;
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;

Modules

array

Safe interface for NumPy ndarray

convert

Defines conversion traits between rust types and numpy data types.

npyffi

Low-Level bindings for NumPy C API.

Structs

FromVecError

Represents that given vec cannot be treated as array.

NotContiguousError

Represents that the array is not contiguous.

PyReadonlyArray

Readonly reference of PyArray.

ShapeError

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

Enums

DataType

An enum type represents numpy data type.

Traits

Element

Represents that a type can be an element of PyArray.

Functions

Ix1

Create a one-dimensional index

Ix2

Create a two-dimensional index

Ix3

Create a three-dimensional index

Ix4

Create a four-dimensional index

Ix5

Create a five-dimensional index

Ix6

Create a six-dimensional index

IxDyn

Create a dynamic-dimensional index

Type Definitions

Ix1

one-dimensional

Ix2

two-dimensional

Ix3

three-dimensional

Ix4

four-dimensional

Ix5

five-dimensional

Ix6

six-dimensional

IxDyn

dynamic-dimensional

PyReadonlyArray1

one-dimensional readonly array

PyReadonlyArray2

two-dimensional readonly array

PyReadonlyArray3

three-dimensional readonly array

PyReadonlyArray4

four-dimensional readonly array

PyReadonlyArray5

five-dimensional readonly array

PyReadonlyArray6

six-dimensional readonly array

PyReadonlyArrayDyn

dynamic-dimensional readonly array

c32
c64