bundles / numpy 2.4.4 / numpy / _core / _multiarray_umath / inner
built-in
numpy._core._multiarray_umath:inner
Signature
built-in
inner ( a , b , / ) Summary
Inner product of two arrays.
Extended Summary
Ordinary inner product of vectors for 1-D arrays (without complex conjugation), in higher dimensions a sum product over the last axes.
Parameters
a, b: array_likeIf
aandbare nonscalar, their last dimensions must match.
Returns
out: ndarrayIf
aandbare both scalars or both 1-D arrays then a scalar is returned; otherwise an array is returned.out.shape = (*a.shape[:-1], *b.shape[:-1])
Raises
: ValueErrorIf both
aandbare nonscalar and their last dimensions have different sizes.
Notes
For vectors (1-D arrays) it computes the ordinary inner-product
np.inner(a, b) = sum(a[:]*b[:])More generally, if ndim(a) = r > 0 and ndim(b) = s > 0
np.inner(a, b) = np.tensordot(a, b, axes=(-1,-1))or explicitly
np.inner(a, b)[i0,...,ir-2,j0,...,js-2] = sum(a[i0,...,ir-2,:]*b[j0,...,js-2,:])
In addition a or b may be scalars, in which case
np.inner(a,b) = a*bExamples
Ordinary inner product for vectors:import numpy as np a = np.array([1,2,3]) b = np.array([0,1,0]) np.inner(a, b)Some multidimensional examples:
a = np.arange(24).reshape((2,3,4)) b = np.arange(4) c = np.inner(a, b) c.shape c
a = np.arange(2).reshape((1,1,2)) b = np.arange(6).reshape((3,2)) c = np.inner(a, b) c.shape cAn example where `b` is a scalar:
np.inner(np.eye(2), 7)
See also
Aliases
-
numpy._core._multiarray_umath.inner