Skip to main content

outer

Function outer 

Source
pub fn outer<T>(u: &ArrayView1<'_, T>, v: &ArrayView1<'_, T>) -> Array2<T>
where T: Clone + Zero + Mul<Output = T>,
Expand description

Compute the outer product of two 1D arrays.

Given vectors u of length m and v of length n, returns an m × n matrix M where M[i, j] = u[i] * v[j].

§Examples

use scirs2_core::ops::outer;
use ndarray::array;

let u = array![1.0_f64, 2.0, 3.0];
let v = array![4.0_f64, 5.0];
let m = outer(&u.view(), &v.view());
assert_eq!(m.shape(), &[3, 2]);
assert_eq!(m[[0, 0]], 4.0);
assert_eq!(m[[2, 1]], 15.0);