# Possible bug in in numpy\_interface.algorithms.matmul?

**URL:** https://discourse.vtk.org/t/possible-bug-in-in-numpy-interface-algorithms-matmul/15744
**Category:** Support
**Tags:** numpy\_interface, python
**Created:** [June 18, 2025, 5:05pm UTC](https://discourse.vtk.org/t/possible-bug-in-in-numpy-interface-algorithms-matmul/15744 "2025-06-18T17:05:21Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![scotsman60](https://discourse.vtk.org/user_avatar/discourse.vtk.org/scotsman60/32/6000_2.png) [@scotsman60](https://discourse.vtk.org/u/scotsman60)
#### Post date: [June 18, 2025, 5:05pm UTC](https://discourse.vtk.org/t/possible-bug-in-in-numpy-interface-algorithms-matmul/15744/1 "2025-06-18T17:05:21Z")

</div>

Hello!!!

I’m using VTK 9.4 with Python 3.12

I’m trying to use the numpy\_interface.algorithms.matmul method on a vtkCompositeDataArray and finding that it’s not doing what I expect.

IMO, there’s either an error in matmul or I’m misunderatding the intention of the function

My vtkCompositeDataArray is an array of point coordinates - so each array in the composite is an n\*3 float array and I want to multiply each 3 tuple in every array by a 3x3 matrix.

Currently the method fails with a broadcast error fro the underlying einsum method that implements matmul.

If I look at the implementation of matmul in internal\_algorithms.py I see that for each array in the composite (assuming the arrays are nx3) it’s constructing einsum subscripts ‘..j,..j’ which will never give me matrix mutiply.

If I change the subscrpts to ‘ij,jk-\>ik’ all is well

So my question is whether or not this is a bug or if I’m misunderstanding the intent?

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [June 18, 2025, 10:59pm UTC](https://discourse.vtk.org/t/possible-bug-in-in-numpy-interface-algorithms-matmul/15744/2 "2025-06-18T22:59:19Z")

</div>

According to [this](https://stackoverflow.com/a/47966452/2153955), to do a matrix multiplication with NumPy’s `einsum()`, the call would be indeed `np.einsum("ij, jk -> ik", A, B)` supposing A is nx3 and B is 3x3. Notice the two ‘k’ trailing, not following the usual matrix multiplication notation. I guess that was a coding mistake that went unnoticed/not tested.
