Skip to main content

from_vec2d

Function from_vec2d 

Source
pub fn from_vec2d<T: Clone + Zero>(data: Vec<Vec<T>>) -> Matrix<T>
Expand description

Create a matrix from a rectangular 2D vector.

Each inner Vec is one row. The resulting matrix is stored internally in column-major order.

§Panics

Panics if the row lengths are not all equal or if the rectangular shape’s element count overflows usize. Use try_from_vec2d when row-shaped input comes from users, files, or other fallible boundaries to receive a typed error for ragged rows.

§Examples

use tensor4all_tensorbackend::from_vec2d;

let m = from_vec2d(vec![
    vec![1.0, 2.0],
    vec![3.0, 4.0],
]);
assert_eq!(m.nrows(), 2);
assert_eq!(m.ncols(), 2);
assert_eq!(m[[0, 1]], 2.0);
assert_eq!(m[[1, 0]], 3.0);