pub fn from_vec2<'py>(py: Python<'py>, v: &Vec<Vec<T>>) -> Result<&'py Self, ErrorKind>
    where
        T: Clone,
    {
        let last_len = v.last().map_or(0, |v| v.len());
        if v.iter().any(|v| v.len() != last_len) {
            return Err(ErrorKind::FromVec {
                dim1: v.len(),
                dim2: last_len,
            });
        }
        let dims = [v.len(), last_len];
        let array = Self::new(py, dims, false);
        unsafe {
            for y in 0..v.len() {
                for x in 0..last_len {
                    *array.uget_mut([y, x]) = v[y][x].clone();
                }
            }
        }
        Ok(array)
    }
/// Construct a two-dimension PyArray from `Vec<Vec<T>>`.
///
/// This function checks all dimension of inner vec, and if there's any vec
/// where its dimension differs from others, it returns `ArrayCastError`.
///
/// # Example
/// ```
/// # extern crate pyo3; extern crate numpy; #[macro_use] extern crate ndarray; fn main() {
/// use numpy::PyArray;
/// let gil = pyo3::Python::acquire_gil();
/// let vec2 = vec![vec![1, 2, 3]; 2];
/// let pyarray = PyArray::from_vec2(gil.python(), &vec2).unwrap();
/// assert_eq!(pyarray.as_array(), array![[1, 2, 3], [1, 2, 3]]);
/// assert!(PyArray::from_vec2(gil.python(), &vec![vec![1], vec![2, 3]]).is_err());
/// # }
/// ```
Construct a two-dimension PyArray from `Vec>`.
This function checks all dimension of inner vec, and if there's any vec
where its dimension differs from others, it returns `ArrayCastError`.
Construct a two - dimension PyArray from ` Vec > ` . This function checks all dimension of inner vec and if there ' s any vec where its dimension differs from others it returns ` ArrayCastError ` .
pub fn from_vec2<'py>(py: Python<'py>, v: &Vec<Vec<T>>) -> Result<&'py Self, ErrorKind>
    where
        T: Clone,
    {
        let last_len = v.last().map_or(0, |v| v.len());
        if v.iter().any(|v| v.len() != last_len) {
            return Err(ErrorKind::FromVec {
                dim1: v.len(),
                dim2: last_len,
            });
        }
        let dims = [v.len(), last_len];
        let array = Self::new(py, dims, false);
        unsafe {
            for y in 0..v.len() {
                for x in 0..last_len {
                    *array.uget_mut([y, x]) = v[y][x].clone();
                }
            }
        }
        Ok(array)
    }
pub fn from_vec2 < ' py > ( py : Python < ' py > , v : & Vec < Vec < T > > ) -> Result < & ' py Self , ErrorKind > where T : Clone , { let last_len = v . last ( ) . map_or ( 0 , | v | v . len ( ) ) ; if v . iter ( ) . any ( | v | v . len ( ) != last_len ) { return Err ( ErrorKind :: FromVec { dim1 : v . len ( ) , dim2 : last_len , } ) ; } let dims = [ v . len ( ) , last_len ] ; let array = Self :: new ( py , dims , false ) ; unsafe { for y in 0 .. v . len ( ) { for x in 0 .. last_len { * array . uget_mut ( [ y , x ] ) = v [ y ] [ x ] . clone ( ) ; } } } Ok ( array ) }
Construct a two-dimension PyArray from `Vec<Vec<T>>`.
Construct a two - dimension PyArray from ` Vec<Vec<T >> ` .
py
Python<'py>
v
&Vec<Vec<T>>
py
Python<'py>
v
&Vec<Vec<T>>
example
None
extern crate pyo3; extern crate numpy; #[macro_use] extern crate ndarray; fn main() {
None
}
None