MCPcopy Create free account
hub / github.com/PyO3/rust-numpy / from_iter

Method from_iter

src/array.rs:564–570  ·  view source on GitHub ↗

Construct a one-dimensional array from an [`Iterator`]. If no reliable [`size_hint`][Iterator::size_hint] is available, this method can allocate memory multiple times, which can hurt performance. # Example ``` use numpy::{PyArray, PyArrayMethods}; use pyo3::Python; Python::attach(|py| { let pyarray = PyArray::from_iter(py, "abcde".chars().map(u32::from)); assert_eq!(pyarray.readonly().as_slice

(py: Python<'_>, iter: I)

Source from the content-addressed store, hash-verified

562 /// });
563 /// ```
564 pub fn from_iter<I>(py: Python<'_>, iter: I) -> Bound<'_, Self>
565 where
566 I: IntoIterator<Item = T>,
567 {
568 let data = iter.into_iter().collect::<Vec<_>>();
569 data.into_pyarray(py)
570 }
571}
572
573impl<T: Element> PyArray<T, Ix2> {

Callers

nothing calls this directly

Calls 1

into_pyarrayMethod · 0.80

Tested by

no test coverage detected