Function numpy::inner

source · []
pub fn inner<'py, T, DIN1, DIN2, OUT>(
    array1: &'py PyArray<T, DIN1>,
    array2: &'py PyArray<T, DIN2>
) -> PyResult<OUT> where
    T: Element,
    DIN1: Dimension,
    DIN2: Dimension,
    OUT: ArrayOrScalar<'py, T>, 
Expand description

Return the inner product of two arrays.

NumPy’s documentation has the details.

Examples

Note that this function can either return a scalar…

use pyo3::Python;
use numpy::{inner, pyarray, PyArray0};

Python::with_gil(|py| {
    let vector = pyarray![py, 1.0, 2.0, 3.0];
    let result: f64 = inner(vector, vector).unwrap();
    assert_eq!(result, 14.0);
});

…or an array depending on its arguments.

use pyo3::Python;
use numpy::{inner, pyarray, PyArray0};

Python::with_gil(|py| {
    let vector = pyarray![py, 1, 2, 3];
    let result: &PyArray0<_> = inner(vector, vector).unwrap();
    assert_eq!(result.item(), 14);
});