Basic arithmetic operations (+, -, *, /) are performed element-wise. To avoid consuming the arrays, use references (&) in the operation.
Ownership Rules for Binary Operators (@):
&A @ &A: Produces a new Array (allocates).B @ A: Consumes B, updates it with the result, and returns it.B @ &A: Consumes B, updates it with the result, and returns it.C @= &A: Performs an arithmetic operation in place.
use ndarray::prelude::*;
use ndarray::Array;
use std::f64::INFINITY as inf;
fn main() {
let a = array![[10.,20.,30., 40.,]];
let b = Array::range(0., 4., 1.);
assert_eq!(&a + &b, array![[10., 21., 32., 43.,]]);
assert_eq!(&a - &b, array![[10., 19., 28., 37.,]]);
assert_eq!(&a * &b, array![[0., 20., 60., 120.,]]);
assert_eq!(&a / &b, array![[inf, 20., 15., 13.333333333333334,]]);
}