我有一个2D数组,看起来像这样:
[[0.1, 0.2, 0.4, 0.6, 0.9]
[0.3, 0.7, 0.8, 0.3, 0.9]
[0.7, 0.9, 0.4, 0.6, 0.9]
[0.1, 0.2, 0.6, 0.6, 0.9]]
我想保存数组大于0.6的索引,但我还想保留该位置的值,因此输出为:
[0, 3, 0.6]
[0, 4, 0.9]
[1, 2, 0.7]
等等
为了获得索引,我做了以下操作:
x = np.where(PPCF> 0.6)
high_pc = np.asarray(x).T.tolist()
但如何将该值保持在第三个位置
简单,无循环:
请随意将其转换为列表
这应该起作用:
您可以沿着列和行运行一个循环,检查每个元素是否大于阈值,并将它们保存在列表中
相关问题 更多 >
编程相关推荐