# What is an alternative to unsupported NumPy function 'numpy.matmul'

**URL:** <https://numba.discourse.group/t/what-is-an-alternative-to-unsupported-numpy-function-numpy-matmul/2217>\
**Category:** Support: How do I do ...?\
**Created:** [October 17, 2023, 5:25pm UTC](https://numba.discourse.group/t/what-is-an-alternative-to-unsupported-numpy-function-numpy-matmul/2217 "2023-10-17T17:25:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pauljurczak](https://yyz2.discourse-cdn.com/free1/user_avatar/numba.discourse.group/pauljurczak/32/479_2.png) [@pauljurczak](https://numba.discourse.group/u/pauljurczak)\
**Post date:** [October 17, 2023, 5:25pm UTC](https://numba.discourse.group/t/what-is-an-alternative-to-unsupported-numpy-function-numpy-matmul/2217/1 "2023-10-17T17:25:22Z")

</div>

This script runs fine in Python mode, but function `f()` fails to compile with Numba:

```auto
import numpy as np, numba as nb

@nb.njit(fastmath=True)
def f(mat, p):
  r = np.matmul(mat, p)
  return r[:-1]/r[-1]

mat = np.array([[2.44 , -0.01 , -74.526],
                [0.578, 0.873, -86.261],
                [0.003, -0. , 1.]])
q = [100, 200, 1]
print(f(mat, q))

```

producing this error:

```auto
numba.core.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Use of unsupported NumPy function 'numpy.matmul' or unsupported use of the function.

File "so-20.py", line 5:
def f(mat, p):
  r = np.matmul(mat, p)
  ^

```

Is there a workaround for this? I don’t have to use Numpy for matrix multiplication if there is another library, which works with Numba.

---

<div class="post-metadata">

**Author:** ![Oyibo](https://avatars.discourse-cdn.com/v4/letter/o/4af34b/32.png) [@Oyibo](https://numba.discourse.group/u/Oyibo)\
**Post date:** [October 17, 2023, 9:24pm UTC](https://numba.discourse.group/t/what-is-an-alternative-to-unsupported-numpy-function-numpy-matmul/2217/2 "2023-10-17T21:24:31Z")

</div>

Hey @pauljurczak ,  
Numba has implemented numpy.dot for operations on 1D and/or 2D arrays. You can use an operator like a @ b, too.

```auto
import numpy as np
import numba as nb

@nb.njit(fastmath=True)
def nb_dot(mat, q):
  return np.dot(mat, q)

@nb.njit(fastmath=True)
def nb_op(mat, q):
  return mat @ q

mat = np.array([[2.44 , -0.01 , -74.526],
                [0.578, 0.873, -86.261],
                [0.003, -0. , 1.]])
q = np.array([100., 200, 1])
print(np.matmul(mat, q))
print(nb_dot(mat, q))
print(nb_op(mat, q))
# [167.474 146.139 1.3]
# [167.474 146.139 1.3]
# [167.474 146.139 1.3]

```

---

<div class="post-metadata">

**Author:** ![pauljurczak](https://yyz2.discourse-cdn.com/free1/user_avatar/numba.discourse.group/pauljurczak/32/479_2.png) [@pauljurczak](https://numba.discourse.group/u/pauljurczak)\
**Post date:** [October 17, 2023, 10:58pm UTC](https://numba.discourse.group/t/what-is-an-alternative-to-unsupported-numpy-function-numpy-matmul/2217/3 "2023-10-17T22:58:48Z")

</div>

Thanks a lot. That’s what I was looking for.
