inner
Description
Calculate the inner product of two arrays. It returns the ordinary inner product of vectors for 1-D arrays (without complex conjugation), and returns a sum product over the last axes for arrays in higher dimensions.
Mandatory Input Parameters
Parameter |
Type |
Description |
|---|---|---|
a |
array_like |
The first argument. |
b |
array_like |
The second argument. |
Note that if a and b are nonscalar, their last dimensions must match. Otherwise, an exception is raised.
Optional Input Parameters
None
Return Value
Type |
Description |
|---|---|
ndarray |
Returns the inner product of a and b. If a and b are both scalars or both 1-D arrays, a scalar is returned; otherwise an array is returned. |
Examples
>>> import numpy as np
>>> a = np.array([1,2,3])
>>> b = np.array([0,1,2])
>>> np.inner(a, b)
8
>>>
>>> a = np.arange(24).reshape((2,3,4))
>>> a
array([[[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11]],
[[12, 13, 14, 15],
[16, 17, 18, 19],
[20, 21, 22, 23]]])
>>> b = np.arange(4)
>>> b
array([0, 1, 2, 3])
>>> np.inner(a, b)
array([[ 14, 38, 62],
[ 86, 110, 134]])
>>>
>>> a = np.arange(2).reshape((1,1,2))
>>> b = np.arange(6).reshape((3,2))
>>> np.inner(a, b)
array([[[1, 3, 5]]])
>>>
>>> a = np.eye(2)
>>> a
array([[1., 0.],
[0., 1.]])
>>> np.inner(a, 5)
array([[5., 0.],
[0., 5.]])
>>>
Parent topic: Basic Statistics Functions