这是我尝试过的
use ndarray::{arr2, s};
let mut a = arr2(&[[1, 2, 3],
[4, 5, 6]]);
let b = arr2(&[[2, 3, 3],
[5, 6, 6]]);
a.slice_mut(s![.., ..2]).assign(&a.slice_mut(s![.., 1..]));
由于借用规则(playround link),这显然失败了:
error[E0499]: cannot borrow `a` as mutable more than once at a time
--> src/main.rs:13:38
|
13 | a.slice_mut(s![.., ..2]).assign(&a.slice_mut(s![.., 1..]));
| - ------ ^ second mutable borrow occurs here
| | |
| | first borrow later used by call
| first mutable borrow occurs here
这a
就是我所拥有的,b
也是我想要得到的。
在 numpy 中,它就像a[:, :2] = a[:, 1:]
.
PS也许在nalgebra
板条箱中有一个简单的解决方案?