I was looking to update a row of 2D matrix in rust ndarray, but row_mut
does not seem to allow me to update the row directly.
For example (playground link)
let mut array = array![[1., 2.], [3., 4.]];
let y = array![5., 5.];
array.row_mut(0) += &y;
However it works if I assign the mutable slice to a temporary variable and then do the +=
operation. the the following code works as expected (playground link).
let mut array = array![[1., 2.], [3., 4.]];
let y = array![5., 5.];
let mut z = array.row_mut(0);
z += &y;
Any idea what is causing the behaviour?