bundles / numpy 2.5.0.dev0+git20251130.2de293a / numpy / linalg / matmul
_ArrayFunctionDispatcher
numpy.linalg:matmul
source: build-install/usr/lib/python3.14/site-packages/numpy/linalg/_linalg.py :3325
Signature
def matmul ( x1 , x2 , / ) Summary
Computes the matrix product.
Extended Summary
This function is Array API compatible, contrary to numpy.matmul.
Parameters
x1: array_likeThe first input array.
x2: array_likeThe second input array.
Returns
out: ndarrayThe matrix product of the inputs. This is a scalar only when both
x1,x2are 1-d vectors.
Raises
: ValueErrorIf the last dimension of
x1is not the same size as the second-to-last dimension ofx2.If a scalar value is passed in.
Examples
For 2-D arrays it is the matrix product:a = np.array([[1, 0], [0, 1]]) b = np.array([[4, 1], [2, 2]]) np.linalg.matmul(a, b)✓
a = np.array([[1, 0], [0, 1]]) b = np.array([1, 2]) np.linalg.matmul(a, b) np.linalg.matmul(b, a)✓
a = np.arange(2 * 2 * 4).reshape((2, 2, 4)) b = np.arange(2 * 2 * 4).reshape((2, 4, 2)) np.linalg.matmul(a,b).shape✓
np.linalg.matmul(a, b)[0, 1, 1] sum(a[0, 1, :] * b[0 , :, 1])✗
np.linalg.matmul([2j, 3j], [2j, 3j])
✗np.linalg.matmul([1,2], 3)
✓See also
Aliases
-
numpy.linalg.matmul