我是Rust的新手,我正在try 使用Rust对多个矩阵执行顺序Kronecker乘积,即我想做
在巨 Python 中,我知道我可以做到
import numpy as np
from functools import reduce
X = np.array([[0, 1], [1, 0])
matrices = [X for _ in range(8)]
product = reduce(np.kron, matrices)
并得到想要的结果.如何在铁 rust 中做到同样的事情?
目前,我的铁 rust 代码如下所示:
use ndarray::{array, ArrayBase, OwnedRepr, Dim};
use ndarray::linalg::kron;
use num::complex::Complex64 as Complex;
fn X() -> ArrayBase<OwnedRepr<Complex>, Dim<[usize; 2]>> {
array![
[Complex::new(0.0, 0.0), Complex::new(1.0, 0.0)],
[Complex::new(1.0, 0.0), Complex::new(0.0, 0.0)]
]
}
fn main() {
let mut matrices = Vec::new();
for _ in 0..8 {
matrices.push(X());
}
let product = matrices
.iter()
.reduce(|g1, g2| kron(g1, g2));
}
下面是我得到的误差矩阵:
以下是我不明白的事情:
-
OwnedRepr
:我不确定这到底是为了什么,但这是Rust 分析师建议我做的 - I tried to modify my code according to the error message's suggestion, but I got with no further suggestions on how to process.
我想知道如何解决这个问题,如果有任何关于如何使用Rust进行科学计算的初学者级别的示例文件的建议,我将不胜感激.