Replies: 1 comment
-
Note that you can use arithmetic operations with For example, you can do in-place operations ( use ndarray::prelude::*;
use ndarray::aview_mut2;
fn main() {
let mut data = [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]];
let mut v: ArrayViewMut2<'_, f64> = aview_mut2(&mut data);
v += 0.5;
assert_eq!(v, array![[1.5, 2.5, 3.5], [4.5, 5.5, 6.5], [7.5, 8.5, 9.5]]);
} and non-in-place operations, e.g.: use ndarray::prelude::*;
use ndarray::aview_mut2;
fn main() {
let mut data = [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]];
let v: ArrayViewMut2<'_, f64> = aview_mut2(&mut data);
let o: Array2<f64> = &v + 0.5;
assert_eq!(o, array![[1.5, 2.5, 3.5], [4.5, 5.5, 6.5], [7.5, 8.5, 9.5]]);
} You can also call use ndarray::prelude::*;
use ndarray::aview_mut2;
fn main() {
let mut data = [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]];
let mut v: ArrayViewMut2<'_, f64> = aview_mut2(&mut data);
v.map_inplace(|elem| *elem += 0.5);
assert_eq!(v, array![[1.5, 2.5, 3.5], [4.5, 5.5, 6.5], [7.5, 8.5, 9.5]]);
} Does that answer your question? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have noticed that
ArrayMutView
orArrayView
hasfrom_shape_ptr,
which allows operations likeI am wondering if it is possible to allow converting
data
into a standardndarray::Array
? So the array is not owning, but I still could apply arithmetic operations on them?Beta Was this translation helpful? Give feedback.
All reactions