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])
| 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 | /// |
nothing calls this directly
no test coverage detected