MCPcopy Index your code
hub / github.com/PyO3/rust-numpy / from_slice

Method from_slice

src/array.rs:520–527  ·  view source on GitHub ↗

Construct a one-dimensional array from a [mod@slice]. # Example ``` use numpy::{PyArray, PyArrayMethods}; use pyo3::Python; Python::attach(|py| { let slice = &[1, 2, 3, 4, 5]; let pyarray = PyArray::from_slice(py, slice); assert_eq!(pyarray.readonly().as_slice().unwrap(), &[1, 2, 3, 4, 5]); }); ```

(py: Python<'py>, slice: &[T])

Source from the content-addressed store, hash-verified

518 /// });
519 /// ```
520 pub fn from_slice<'py>(py: Python<'py>, slice: &[T]) -> Bound<'py, Self> {
521 unsafe {
522 let array = PyArray::new(py, [slice.len()], false);
523 let mut data_ptr = array.data();
524 clone_elements(py, slice, &mut data_ptr);
525 array
526 }
527 }
528
529 /// Construct a one-dimensional array from a [`Vec<T>`][Vec].
530 ///

Callers

nothing calls this directly

Calls 3

clone_elementsFunction · 0.85
lenMethod · 0.80
dataMethod · 0.80

Tested by

no test coverage detected