Get a mutable reference to a subarray in an ndarray

Suppose there is an ndarray "a" of dimension (3,4,5).
"a" can be written as [b0,b1,b2]. I need a mutable reference to b1.

It's a bit confusing to put it in code without an example. Can you show me sample code on how to do this?

What type is b1 supposed to be?

ndarray of dimension (4,5).

OK. There are 3 possible (4, 5) ndarray in (3, 4, 5). Do you need a specific one or do you want an iterator over all 3 of them?

Both actually.

You can achieve this using slice_mut.

let mut b0 = a.slice_mut::<Ix2>(s![0, .., ..]);
let mut b1 = a.slice_mut::<Ix2>(s![1, .., ..]);
let mut b2 = a.slice_mut::<Ix2>(s![2, .., ..]);

Note that a is of the type Array and b0,b1,b2 are of the type ArrayViewMut.

Visit this page for more information.