question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BUG: np.matmul fails on np.matrix of integers

See original GitHub issue
>>> a = np.matrix([[1,1],[1,2]])
>>> a
matrix([[1, 1],
        [1, 2]])
>>> b = np.array([1,2])
>>> b
array([1, 2])
>>> np.matmul(a,b)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
RuntimeError: Iterator automatic output has an array subtype which changed the dimensions of the output
>>> a = a.astype(np.float64)
>>> a
matrix([[ 1.,  1.],
        [ 1.,  2.]])
>>> np.matmul(a,b)
matrix([[ 3.,  5.]])

When a.dtype is np.int32, we cannot do np.matmul on a and b. But after changing the data type to np.float64, it works. Anyone know why is that?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
eric-wiesercommented, Mar 18, 2018

That’s a bizarre error. It might be due to you using np.matrix, which you should really avoid. np.array works just fine for 2d arrays, especially if you’re using matmul

0reactions
mattipcommented, Dec 12, 2018

now that matmul is a ufunc, this works

>>> a = np.matrix([[1,1],[1,2]])
>>> b = np.array([1,2])
>>> np.matmul(a,b)
matrix([[3, 5]])
Read more comments on GitHub >

github_iconTop Results From Across the Web

Numpy matrix multiplication causing windows exception
Every time I try to run either np.dot(A, B) , np.matmul(A, B) or A @ B with square two-dimensional Numpy arrays I get...
Read more >
NumPy Matrix Multiplication — np.matmul() and @ [Ultimate ...
In this article, we'll explain everything you need to know about matrix multiplication in NumPy. np.matmul() vs np.dot() vs @ Matrix Multiplication ...
Read more >
numpy.matmul — NumPy v1.24 Manual
If the first argument is 1-D, it is promoted to a matrix by prepending a 1 to its dimensions. After matrix multiplication the...
Read more >
2.2. Advanced NumPy - Scipy Lecture Notes
proper error for non-integer types. I'm using NumPy 1.4.1, built from the official tarball, on Windows. 64 ...
Read more >
Chapter 4. NumPy Basics: Arrays and Vectorized Computation
In addition to np.array , there are a number of other functions for creating new ... In complex computations, you may accrue some...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found