将布尔数组(即True False)转换为实际值?

时间:2020-04-21 22:43:11

标签: python arrays numpy boolean

我正在尝试将数组“ v”中的所有真值转换为它们的实际数字。任何建议将不胜感激。

import numpy as np
from numpy import load

dict_data = load('E_starData.npz')
EStar = dict_data['arr_0']
v = np.greater(EStar, 0.1)
print(v) #prints an array of true and false values, would like to display true values as the actual number

代码正在提取包含所有数据的已保存zip文件。

2 个答案:

答案 0 :(得分:1)

您可以使用:

v = EStar * (EStar>0.1)

答案 1 :(得分:0)

从一开始就可能有更好的方法来解决该问题,但是要构建您的代码:

print([val for bool, val in zip(v, Estar) if bool])