-1
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])
使用Python 3不過,我得到爲什麼犯規`searchsorted`工作一樣在Python 3和Python 2
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()
我的問題是:是在Python3或錯誤此預期的行爲?無論如何:我怎樣才能讓我的Python 2代碼兼容Python版本?
爲什麼你對象數組滿弦的搜索整數? – user2357112
這不是關於實際搜索的內容。這裏有一個相關的問題:http://stackoverflow.com/q/3270680/2285236 – ayhan
爲什麼downvotes? – wirrbel