pub trait IntoPyArray {
    type Item: Element;
    type Dim: Dimension;
    fn into_pyarray<'py>(
        self,
        _: Python<'py>
    ) -> &'py PyArray<Self::Item, Self::Dim>; }
Expand description

Conversion trait from some rust types to PyArray.

This trait takes self, which means it holds a pointer to Rust heap, until resize or other destructive method is called.

In addition, if you construct PyArray via this method, you cannot use some destructive methods like resize.

Example

use numpy::{PyArray, IntoPyArray};
pyo3::Python::with_gil(|py| {
    let py_array = vec![1, 2, 3].into_pyarray(py);
    assert_eq!(py_array.readonly().as_slice().unwrap(), &[1, 2, 3]);
    assert!(py_array.resize(100).is_err()); // You can't resize owned-by-rust array.
});

Associated Types

Required methods

Implementations on Foreign Types

Implementors