4 Matrix
4.1 Declare matrix
- You can declare matrix by various ways.
- R’s way - Default
- MATLAB’s way
- Python’s way
- Other macro
4.1.1 R’s way
- Description: Same as R -
matrix(Vector, Row, Col, Shape)
- Type:
matrix(Vec<T>, usize, usize, Shape) where T: std::convert::Into<f64> + Copy
Shape
:Enum
for matrix shape -Row
&Col
fn main() { let a = matrix(c!(1,2,3,4), 2, 2, Row); a.print(); // c[0] c[1] // r[0] 1 2 // r[1] 3 4 let b = matrix(c!(1,2,3,4), 2, 2, Col); b.print(); // c[0] c[1] // r[0] 1 3 // r[1] 2 4 }
4.1.4 Other macro
For Peroxide
,
fn main() {
let a = matrix!(1;4;1, 2, 2, Row);
a.print();
// c[0] c[1]
// r[0] 1 2
// r[1] 3 4
}