Just learning some rust. I'm using ndarray
and I need to construct a zero matrix copying the dimension from another matrix. I tried
fn make_0(matrix: Array2<i32>) -> Array2<i32> {
Array2::zeros(matrix.shape())
}
But this does not compile:
error[E0271]: type mismatch resolving `<&[usize] as ShapeBuilder>::Dim == Dim<[usize; 2]>`
--> src/lib.rs:62:9
|
62 | Array2::zeros(matrix.shape())
| ^^^^^^^^^^^^^ expected array `[usize; 2]`, found struct `IxDynImpl`
|
= note: expected struct `Dim<[usize; 2]>`
found struct `Dim<IxDynImpl>`
I can solve it with
fn make_0(matrix: Array2<i32>) -> Array2<i32> {
Array2::zeros((matrix.shape()[0], matrix.shape()[1]))
}
But I guess there's something better and I'm lost with types here.