Function extendr_api::prelude::aview_mut2
source · pub fn aview_mut2<A, V>(
xs: &mut [V],
) -> ArrayBase<ViewRepr<&mut A>, Dim<[usize; 2]>>where
V: FixedInitializer<Elem = A>,
Expand description
Create a two-dimensional read-write array view with elements borrowing xs
.
Panics if the product of non-zero axis lengths overflows isize
. (This
can only occur when V
is zero-sized.)
§Example
use ndarray::aview_mut2;
// The inner (nested) array must be of length 1 to 16, but the outer
// can be of any length.
let mut data = [[0.; 2]; 128];
{
// Make a 128 x 2 mut array view then turn it into 2 x 128
let mut a = aview_mut2(&mut data).reversed_axes();
// Make the first row ones and second row minus ones.
a.row_mut(0).fill(1.);
a.row_mut(1).fill(-1.);
}
// look at the start of the result
assert_eq!(&data[..3], [[1., -1.], [1., -1.], [1., -1.]]);