matmul
Description
Calculate the matrix product of two arrays.
Mandatory Input Parameters
Parameter |
Type |
Description |
|---|---|---|
x1 |
array_like |
The first argument. |
x2 |
array_like |
The second argument. |
Note that scalars are not allowed. Otherwise, an exception is raised.
Optional Input Parameters
Parameter |
Type |
Default Value |
Description |
|---|---|---|---|
out |
ndarray |
None |
Location into which the result is stored. If provided, it must have a shape that matches the signature (n,k),(k,m)->(n,m). If not provided or None, a freshly-allocated array is returned. |
**kwargs |
- |
- |
Return Value
Type |
Description |
|---|---|
ndarray |
Matrix product of the inputs. This is a scalar only when both x1 and x2 are 1-D vectors. |
Examples
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | >>> 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