我想对二维数组进行一些线性计算,因此想构建自己的矩阵。
use ndarray::Array2;
// [0,0,0,0,0]
// [0,0,0,0,0]
// [0,0,0,0,0]
// [0,0,0,0,0]
let mut matrix:Array2<u8> = Array2::zeros((4, 5));
// Goal
// [0,0,1,0,0]
// [0,0,1,0,0]
// [0,1,0,1,0]
// [0,0,1,0,0]
matrix[3][0] = 1;
matrix[3][1] = 1;
matrix[2][2] = 1;
matrix[2][4] = 1;
//...
语法是使用一个索引和一个数组:
matrix[[3, 0]] = 1;