【发布时间】:2019-07-12 06:55:36
【问题描述】:
我正在使用numpy searchsort() 函数来查找numpy 数组的索引。它仅适用于某些阵列。出了什么问题(下面的实现)?
import numpy as np
#specify the dtype in RV
RV = np.array([
np.array([0.23, 2.5, 5.0, 7.1]),
np.array(['a1', 'a2']),
np.array(['b2', 'b1'])
], dtype=object)
print(RV)
def Rules():
global r
r = np.array(np.meshgrid(*RV), dtype=object).T.reshape(-1,len(RV))
return r
Rules()
print(r)
print(RV[0].searchsorted(r[:,0])) #working
print(RV[1].searchsorted(r[:,1])) #working
print(RV[2].searchsorted(r[:,2])) #not working
【问题讨论】:
-
既然
RV[2]未排序,请使用sorterarg。
标签: python python-3.x numpy indexing