In Python, say I have two 4D NumPy arrays (the exact number number of dimensions doesn't matter too much other than it being multi-dimensional):
import numpy as np
a = np.ones((4, 5, 6, 7))
b = np.zeros((4, 5, 6, 7))
If I want to assign a certain slice from b into a, I could do, e.g.,:
a[1:3, 0:2, 1::2, :] = b[1:3, 0:2, 1::2, :]
If I have two 4D rust ndarray's, e.g.,
use ndarray::prelude::*
fn main() {
let mut a = Array4::<f64>::ones((4, 5, 6, 7));
let b = Array4::<f64>::zeros((4, 5, 6, 7));
}
how would I go about doing an equivalent assignment of a slice of b into a?
This is rather similar, but (I think) not quite the same as:
- ndarray rust, change values of a slice
- Is there a Rust ndarray equivalent for numpy arithmetic on a slice?
and there is information in this Github thread.
The way I have found to do this is using the
slice_mutmethod, theassignmethod and thes!slice macro. For an exact match of the case above, we could do: