jax.numpy.matmul#

jax.numpy.matmul(a, b, *, precision=None, preferred_element_type=None, out_sharding=None)[source]#

Perform a matrix multiplication.

JAX implementation of numpy.matmul().

Parameters:
Returns:

array containing the matrix product of the inputs. Shape is a.shape[:-1] if b.ndim == 1, otherwise the shape is (..., K, M), where leading dimensions of a and b are broadcast together.

Return type:

Array

See also

Examples

Vector dot products:

>>> a = jnp.array([1, 2, 3])
>>> b = jnp.array([4, 5, 6])
>>> jnp.matmul(a, b)
Array(32, dtype=int32)

Matrix dot product:

>>> a = jnp.array([[1, 2, 3],
...                [4, 5, 6]])
>>> b = jnp.array([[1, 2],
...                [3, 4],
...                [5, 6]])
>>> jnp.matmul(a, b)
Array([[22, 28],
       [49, 64]], dtype=int32)

For convenience, in all cases you can do the same computation using the @ operator:

>>> a @ b
Array([[22, 28],
       [49, 64]], dtype=int32)