我正在使用ndarray
并尝试对一些数组进行切片。这有效
let y = arr2(&[[ 6, 5, 4],
[12, 11, 10]]);
let ip = y.slice(s![0, ..]);
println!("IP {}", ip);
但是这个
let y = arr2(&[[ 6, 5, 4],
[12, 11, 10]]);
let ip = y.slice(s![0, ..]);
println!("IP {}", ip[0]);
不编译。到底是怎么回事?
编译错误是:
Error[E0277]: the trait bound `i32: Dimension` is not satisfied
....
println!("IP {}", ip[0]);
| ^^^^^ the trait `Dimension` is not implemented for `i32`
| = note: required because of the requirements on the impl of `std::ops::Index<i32>` for `ArrayBase<ViewRepr<&i32>, i32>`
有其他错误
error[E0308]: mismatched types
....
| let ip = y.slice(s![0, ..]);
| ^^^^^^^^^^^^^^^^^^ expected `i32`, found struct `Dim`
|
= note: expected type `i32`
found struct `Dim<[usize; 1]>`