from-python-to-numpy icon indicating copy to clipboard operation
from-python-to-numpy copied to clipboard

Error in the find_index functon

Open fat-crocodile opened this issue 3 years ago • 1 comments

Hi!

Z = base[6:2:-1, 5::-1]
find_index(base, Z)

produces an exception

TypeError: unsupported operand type(s) for -: 'NoneType' and 'int'

The problem is here, in line 43 https://github.com/rougier/from-python-to-numpy/blob/eb21651fc84d132414603e5a16d93f54ef45ec99/code/find_index.py#L41-L45

We've checked that stop is not None, but step is less than zero and we didn't check start, BOOM!

I suggest code like this:

        if step is not None:
            if step < 0:
                start, stop = stop, start
            if stop is not None:
                stop += np.sign(step)

fat-crocodile avatar Jul 19 '22 23:07 fat-crocodile

Sorry for late reply. You mean your fix solve the problem ? Could you make a PR?

rougier avatar Aug 08 '22 14:08 rougier