Skip to main content

bmat_from_string

Function bmat_from_string 

Source
pub fn bmat_from_string<T: Clone>(_description: &str) -> Result<Array<T>>
Expand description

Interpret an object as a matrix and build a matrix from string representations

This function emulates NumPy’s bmat functionality, allowing you to create matrices from string representations like “A B; C D” or nested arrays.

§Arguments

  • obj - String description of the matrix or nested array structure

§Returns

A 2D array built from the specified blocks

§Examples

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

// Create a 2x2 block matrix from string description
// "A B; C D" where A, B, C, D are variable names in scope
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]);

// The result would be a 4x4 matrix with these blocks