我想有条件地填充一个给定列表的numpy数组
遍历my_list
numpy数组的每个元素并查找dup_list
以查看它是否有pair值,例如,1的pair值为35。然后,将my_list
中的1更改为35
my_list = np.array([1, 2, 3, 4])
dup_list = [[1, 35], [4, 31]]
my_list
的理想结果:
array([35, 2, 3, 31])
我下面的代码没有改变任何东西
for dup in dup_list:
np.where(my_list==dup[0], dup[1], my_list)
my_list
array([1, 2, 3, 4])
我想这就是你想做的:
结果:
相关问题 更多 >
编程相关推荐