@@ -482,28 +482,6 @@ impl<T: TypeNum, D: Dimension> PyArray<T, D> {
482482 unsafe { ArrayViewMut :: from_shape_ptr ( self . ndarray_shape ( ) , self . data ( ) ) }
483483 }
484484
485- /// Get a copy of `PyArray` as
486- /// [`ndarray::Array`](https://docs.rs/ndarray/0.12/ndarray/type.Array.html).
487- ///
488- /// # Example
489- /// ```
490- /// # #[macro_use] extern crate ndarray; extern crate pyo3; extern crate numpy; fn main() {
491- /// use numpy::PyArray;
492- /// let gil = pyo3::Python::acquire_gil();
493- /// let py_array = PyArray::arange(gil.python(), 0, 4, 1).reshape([2, 2]).unwrap();
494- /// assert_eq!(
495- /// py_array.to_owned_array(),
496- /// array![[0, 1], [2, 3]]
497- /// )
498- /// # }
499- /// ```
500- pub fn to_owned_array ( & self ) -> Array < T , D > {
501- unsafe {
502- let vec = self . as_slice ( ) . to_owned ( ) ;
503- Array :: from_shape_vec_unchecked ( self . ndarray_shape ( ) , vec)
504- }
505- }
506-
507485 /// Get an immutable reference of a specified element, without checking the
508486 /// passed index is valid.
509487 ///
@@ -620,6 +598,30 @@ impl<T: TypeNum, D: Dimension> PyArray<T, D> {
620598 }
621599}
622600
601+ impl < T : TypeNum + Clone , D : Dimension > PyArray < T , D > {
602+ /// Get a copy of `PyArray` as
603+ /// [`ndarray::Array`](https://docs.rs/ndarray/0.12/ndarray/type.Array.html).
604+ ///
605+ /// # Example
606+ /// ```
607+ /// # #[macro_use] extern crate ndarray; extern crate pyo3; extern crate numpy; fn main() {
608+ /// use numpy::PyArray;
609+ /// let gil = pyo3::Python::acquire_gil();
610+ /// let py_array = PyArray::arange(gil.python(), 0, 4, 1).reshape([2, 2]).unwrap();
611+ /// assert_eq!(
612+ /// py_array.to_owned_array(),
613+ /// array![[0, 1], [2, 3]]
614+ /// )
615+ /// # }
616+ /// ```
617+ pub fn to_owned_array ( & self ) -> Array < T , D > {
618+ unsafe {
619+ let vec = self . as_slice ( ) . to_vec ( ) ;
620+ Array :: from_shape_vec_unchecked ( self . ndarray_shape ( ) , vec)
621+ }
622+ }
623+ }
624+
623625impl < T : TypeNum > PyArray < T , Ix1 > {
624626 /// Construct one-dimension PyArray from slice.
625627 ///
0 commit comments