有沒有一種快速的方法可以將數(shù)組的每個元素與唯一標(biāo)識符列表中的每個元素進(jìn)行比較?使用 for 循環(huán)遍歷每個唯一值可以工作,但速度太慢而無法使用。我一直在尋找矢量化解決方案,但沒有成功。任何幫助將不勝感激!arrStart = []startRavel = startInforce['pol_id'].ravel()for policy in unique_policies: arrStart.append(np.argwhere(startRavel == policy))樣本輸入:startRavel = [1,2,2,2,3,3]unique_policies = [1,2,3]示例輸出:arrStart = [[0], [1,2,3],[4,5]]新數(shù)組的長度與唯一值數(shù)組的長度相同,但每個元素都是大數(shù)組中與該唯一值匹配的所有行的列表。
數(shù)組之間的交集索引
ibeautiful
2021-11-02 10:14:16