搜索具有多个值的Numpy数组

搜索具有多个值的Numpy数组,第1张

搜索具有多个值的Numpy数组

方法1:
使用

np.in1d
-

a[np.in1d(a[:,0], num_list)]

方法2:
使用

np.searchsorted
-

num_arr = np.sort(num_list) # Sort num_list and get as array# Get indices of occurrences of first column in num_listidx = np.searchsorted(num_arr, a[:,0])# Take care of out of bounds casesidx[idx==len(num_arr)] = 0out = a[a[:,0] == num_arr[idx]]


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5673822.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存