blosc2.matmul#

blosc2.matmul(x1: NDArray, x2: NDArray, **kwargs: Any) NDArray#

Computes the matrix product between two Blosc2 NDArrays.

Parameters:
  • x1 (NDArray) – The first input array.

  • x2 (NDArray) – The second input array.

  • kwargs (Any, optional) – Keyword arguments that are supported by the empty() constructor.

Returns:

out – The matrix product of the inputs. This is a scalar only when both x1, x2 are 1-d vectors.

Return type:

NDArray

Raises:

ValueError

If the last dimension of x1 is not the same size as the second-to-last dimension of x2.

If a scalar value is passed in.

References

numpy.matmul

Examples

For 2-D arrays it is the matrix product:

>>> import numpy as np
>>> import blosc2
>>> a = np.array([[1, 2],
...               [3, 4]])
>>> nd_a = blosc2.asarray(a)
>>> b = np.array([[2, 3],
...               [2, 1]])
>>> nd_b = blosc2.asarray(b)
>>> blosc2.matmul(nd_a, nd_b)
array([[ 6,  5],
       [14, 13]])

For 2-D mixed with 1-D, the result is the usual.

>>> a = np.array([[1, 3],
...               [0, 1]])
>>> nd_a = blosc2.asarray(a)
>>> v = np.array([1, 2])
>>> nd_v = blosc2.asarray(v)
>>> blosc2.matmul(nd_a, nd_v)
array([7, 2])
>>> blosc2.matmul(nd_v, nd_a)
array([1, 5])