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.

`np.multiply` vs. `*`

See original GitHub issue

In the course of our work over on dipy, we stumbled into the following behavior:

The following line: https://github.com/nipy/dipy/blob/master/dipy/denoise/shift_twist_convolution.pyx#L68

raises this error (on np 1.11, but not earlier):

Traceback (most recent call last):
  File "contextual_enhancement.py", line 149, in <module>
    sh_order=8, test_mode=True)
  File "dipy/denoise/shift_twist_convolution.pyx", line 68, in dipy.denoise.shift_twist_convolution.convolve (dipy/denoise/shift_twist_convolution.c:2147)
TypeError: 'numpy.float64' object cannot be interpreted as an index

When changed to this:

https://github.com/stephanmeesters/dipy/blob/enhance_5d_update_pr/dipy/denoise/shift_twist_convolution.pyx#L69

This error no longer occurs. What does the error mean (it’s a bit opaque in this context), and how do we avoid it in the future?

Thanks!

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:19 (17 by maintainers)

github_iconTop GitHub Comments

1reaction
sebergcommented, Mar 17, 2016

The reason should be that output is actually a sequence and not an ndarray but you actually

0reactions
sebergcommented, May 27, 2021

Close it, as the last comment said:

[1, 2, 3] * np.float64(4.1)

raises and mismatches with 0-D arrays. But that is tricky and most of the discussion is about things that are not relevant anymore. We should just open a new issue when we run into it again.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Numpy np.multiply vs *-Operator [duplicate] - Stack Overflow
There is no difference. However, the np.multiply function can take in additional, optional arguments, making it more versatile.
Read more >
numpy.multiply — NumPy v1.24 Manual
Input arrays to be multiplied. If x1.shape != x2.shape , they must be broadcastable to a common shape (which becomes the shape of...
Read more >
How to Use the Numpy Multiply Function - Sharp Sight
Here, np.multiply is multiplying together the values of each input matrix, element-wise. And image that shows how np.multiply multiples two same ...
Read more >
What Should I Use for Dot Product and Matrix Multiplication?
np.multiply is basically the same as * . It is a NumPy 's version of element-wise multiplication instead of Python's native operator ...
Read more >
numpy.multiply() in Python - GeeksforGeeks
numpy.multiply() function is used when we want to compute the multiplication of two array. It returns the product of arr1 and arr2, element-wise ......
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