我有两个这样的数组
a = 点1[:2]
,b = 点2[:2]
它们的长度相等。现在我想找到 a
中的重复值及其在 b
中各自的索引。一旦我有了这些指数,我想计算均方根。
我尝试过以下方法:
b = point2[:2]
idx = np.argsort(b)
sorted_z_predval = b[idx]
vals, idx_start, count =
np.unique(sorted_z_predval, return_counts=True, return_index=True)
filt = np.split(idx, idx_start[1:])
vals = vals[count >1]
b_uniq = filter(lambda x: x.size>1, filt)`
现在我得到了值重复多次的索引。我需要在 a = point1[:2]
中找到等效的对索引
我对这一点感到震惊。
如有任何帮助,我们将不胜感激。谢谢。
最佳答案
numpy_indexed包(免责声明:我是它的作者)包含将以高效和矢量化的方式执行这些类型的操作的功能:
import numpy_indexed as npi
idx = npi.indices(b, npi.unique(a))
请注意,您可以使用例如 npi.indices(b, npi.unique(a), Missing=-1)
来获取 idx 中的 -1 值,其中没有对应的值b 中的条目。
关于python - 查找一个数组中的相同值以及另一个数组中的等价对,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57540676/