Skip to main content

bmat

Function bmat 

Source
pub fn bmat<T: Clone>(obj: &[Vec<&Array<T>>]) -> Result<Array<T>>
Expand description

Convenient alias for bmat_from_arrays

This provides the main bmat functionality for creating block matrices.

§Arguments

  • obj - Nested array structure representing the matrix blocks

§Returns

A 2D array built from the specified blocks

§Examples

use numrs2::prelude::*;
use numrs2::array_ops::joining::bmat;

let a = Array::from_vec(vec![1, 2, 3, 4]).reshape(&[2, 2]);
let b = Array::from_vec(vec![5, 6, 7, 8]).reshape(&[2, 2]);
let c = Array::from_vec(vec![9, 10, 11, 12]).reshape(&[2, 2]);
let d = Array::from_vec(vec![13, 14, 15, 16]).reshape(&[2, 2]);

let blocks = vec![
    vec![&a, &b],
    vec![&c, &d],
];
let result = bmat(&blocks).expect("operation should succeed");
assert_eq!(result.shape(), vec![4, 4]);