【发布时间】:2021-06-26 22:16:57
【问题描述】:
我需要用我指定的形状制作一个二维数组并随机填充。
我尝试了下面的代码,但它对我大喊大叫
pub fn fill_shape(x:i32 , y:i32){
let mut rng = rand::thread_rng();
let mut a = vec![];
for x in 0..(x*y)
{
a.push(rng.gen_range(0.0..1.0));
}
let mut temp = ndarray::Array::from_shape_vec((x, y),a);
}
当我执行 (2,2) 之类的操作时它会起作用 错误信息
error[E0277]: the trait bound `(i32, i32): Dimension` is not satisfied
--> src\mynn.rs:42:20
|
42 | let mut temp = ndarray::Array::from_shape_vec((x, y),a);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Dimension` is not implemented for `(i32, i32)`
|
= note: required because of the requirements on the impl of `From<(i32, i32)>` for `StrideShape<(i32, i32)>`
= note: required because of the requirements on the impl of `Into<StrideShape<(i32, i32)>>` for `(i32, i32)`
= note: required by `ndarray::impl_constructors::<impl ArrayBase<S, D>>::from_shape_vec`
【问题讨论】:
-
欢迎来到 SO。请发布错误消息。
-
添加了错误信息,@SakuraKinomoto
-
我看到了,谢谢你这样做。我不是 rust 专家,我建议您将错误发布给有更好知识的人可以帮助您。
标签: rust