场景:
数组recalls和precisions,计算 ,
数组对应元素相乘
recalls = np.array([0, 0, 0, 0.1, 0.1, 0.1, 0.5, 0.3, 0.3])
precisions = np.array([0, 0, 0, 1, 0.3, 0.3, 0.3, 0.3, 0.6])
f1_scores = 2*recalls*precisions/(recalls+precisions)
特定元素赋值
给np数组中为nan的数值赋值为零
f1_scores[np.isnan(f1_scores)] = 0
错误写法
f1_scores[f1_scores==np.nan] = 0
求numpy数组中最大元素索引
max_index = np.argmax(f1_scores)