In [7]: a
Out[7]: array(['107', '207', '307', '407'], dtype=object)
In [8]: v
Out[8]: array([207, 305, 407, 101])
In [9]: np.searchsorted(a, v)
Out[9]: array([0, 0, 0, 0])
With Python 3 however, I get
In [20]: a
Out[20]: array(['107', '207', '307', '407'], dtype=object)
In [21]: v
Out[21]: array([207, 305, 407, 101])
In [22]: np.searchsorted(a, v)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-22-52fb08e43089> in <module>()
----> 1 np.searchsorted(a, v)
/tmp/py3test/lib/python3.4/site-packages/numpy/core/fromnumeric.py in searchsorted(a, v, side, sorter)
1091 except AttributeError:
1092 return _wrapit(a, 'searchsorted', v, side, sorter)
-> 1093 return searchsorted(v, side, sorter)
1094
1095
TypeError: unorderable types: str() > int()
My question would be: Is this expected behaviour on Python3 or a bug? And in any case: How can I make my Python 2 code compatible with both Python versions?