pub fn from_exact_iter(py: Python, iter: impl ExactSizeIterator<Item = T>) -> &Self {
        let array = Self::new(py, [iter.len()], false);
        unsafe {
            for (i, item) in iter.enumerate() {
                *array.uget_mut([i]) = item;
            }
        }
        array
    }
/// Construct one-dimension PyArray from a type which implements
/// [`ExactSizeIterator`](https://doc.rust-lang.org/std/iter/trait.ExactSizeIterator.html).
///
/// # Example
/// ```
/// # extern crate pyo3; extern crate numpy; fn main() {
/// use numpy::PyArray;
/// use std::collections::BTreeSet;
/// let gil = pyo3::Python::acquire_gil();
/// let vec = vec![1, 2, 3, 4, 5];
/// let pyarray = PyArray::from_iter(gil.python(), vec.iter().map(|&x| x));
/// assert_eq!(pyarray.as_slice(), &[1, 2, 3, 4, 5]);
/// # }
/// ```
Construct one-dimension PyArray from a type which implements
[`ExactSizeIterator`].
Construct one - dimension PyArray from a type which implements [ ` ExactSizeIterator ` ] .
pub fn from_exact_iter(py: Python, iter: impl ExactSizeIterator<Item = T>) -> &Self {
        let array = Self::new(py, [iter.len()], false);
        unsafe {
            for (i, item) in iter.enumerate() {
                *array.uget_mut([i]) = item;
            }
        }
        array
    }
pub fn from_exact_iter ( py : Python , iter : impl ExactSizeIterator < Item = T > ) -> & Self { let array = Self :: new ( py , [ iter . len ( ) ] , false ) ; unsafe { for ( i , item ) in iter . enumerate ( ) { * array . uget_mut ( [ i ] ) = item ; } } array }
Construct one-dimension PyArray from a type which implements
[`ExactSizeIterator`](https://doc.rust-lang.org/std/iter/trait.ExactSizeIterator.html).
Construct one - dimension PyArray from a type which implements [ ` ExactSizeIterator ` ] ( https : // doc . rust - lang . org / std / iter / trait . ExactSizeIterator . html ) .
py
Python
iter
impl ExactSizeIterator<Item = T>
py
Python
iter
impl ExactSizeIterator<Item = T>
example
None
extern crate pyo3; extern crate numpy; fn main() {
use numpy::PyArray;
use std::collections::BTreeSet;
let gil = pyo3::Python::acquire_gil();
let vec = vec![1, 2, 3, 4, 5];
let pyarray = PyArray::from_iter(gil.python(), vec.iter().map(|&x| x));
assert_eq!(pyarray.as_slice(), &[1, 2, 3, 4, 5]).
use numpy :: PyArray ; use std :: collections :: BTreeSet ; let gil = pyo3 :: Python :: acquire_gil () ; let vec = vec! [ 1 2 3 4 5 ] ; let pyarray = PyArray :: from_iter ( gil . python () vec . iter () . map ( |&x| x )) ; assert_eq! ( pyarray . as_slice () & [ 1 2 3 4 5 ] ) .
}
None