Yesterday I asked here a question about a weird behavior of python range().
I accidentally used range() instead of np.arange(). But depending on the
input int-type it works for mathematical operations or not.
It was in a huge context, so I simplified the problem.
import numpy as np
"""
DOES WORK
"""
x1 = np.intc(545)
x2 = np.intc(1048)
x_axis = range(x1, x2)
test = (x_axis - x1) # should throw exception, but works
type(x_axis[0]) # numpy.int32 / intc
"""
DOESNT WORK
"""
t1 = 545
t2 = 1048
t_axis = range(t1, t2)
test2 = (t_axis - t1) # throws TypeError unsupported operand type(s) for -: 'range' and 'int'
Background: The reason for using intc-datatype is that my program performs some other tasks like peakfinding etc. and I use some list-comprehensions for generating a list out of the calculated peaks. After some other steps, I use x1 and x2 out of this peak-list (which isn't a normal list of ints obviously). So I changed yesterday my code and generated a new list and then the exception occured. My guess is that numpy/scipy uses internally intc.
Can someone explain this behavior?