Why does numpy silently convert my int array to strings when calling searchsorted?
问题 I found a nasty bug in my code where I forgot to convert an integer from str to int before looking it up in a sorted array of integers. Having fixed it, I am still surprised that this didn't cause an explicit exception. Here's a demo: In [1]: import numpy as np In [2]: a = np.arange(1000, dtype=int) In [3]: a.searchsorted('15') Out[3]: 150 In [4]: a.searchsorted('150') Out[4]: 150 In [5]: a.searchsorted('1500') Out[5]: 151 In [6]: a.searchsorted('foo') Out[6]: 1000 With a float array this