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:
- Created 6 years ago
- Comments:6 (6 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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 usingmatmul
now that matmul is a ufunc, this works