试图在两个执行算术运算时,我有一个问题,Array1
在第ndarray箱。
我试图将我的问题简化为以下形式:
#[macro_use(array)]
extern crate ndarray;
use ndarray::Array1;
fn main() {
let a: Array1<i8> = array![1, 2, 3];
let baz = &a - array![1, 2, 3];
println!("{:#?}", baz);
}
它失败并显示:
|
8 | let baz = &a - array![1, 2, 3];
| ^ expected struct `ndarray::ArrayBase`, found i8
|
根据文档,我应该能够减去两个Array1
s并array!
创建一个Array1
。
我做错了什么?
我应该更仔细地阅读文档:
&A @ &A which produces a new Array
B @ A which consumes B, updates it with the result, and returns it
B @ &A which consumes B, updates it with the result, and returns it
C @= &A which performs an arithmetic operation in place
&A @ B
由于某种原因,没有任何情况。第二个参数不能使用。要么没有,要么只有第一个。因为我不想a
在这里被消耗,所以这就是为什么我需要引用array!
宏的返回值的原因。
所以解决方案是:
let baz = &a - &array![1, 2, 3];
编译器错误在这里并没有真正帮助...
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句