如何获得 0/1 作为二进制预测输出而不是概率?

How to get 0/1 as binary prediction output instead of probabilities?

我训练了一个神经网络模型,得到的预测结果概率在01之间,如何将它们转换成0/1而不是小数?我设法将它们更改为布尔值:

y_pred

output:
array([[0.05447599],
       [0.09883076],
       [0.11023161],
       ...,
       [0.19569233],
       [0.07266018],
       [0.08473385]], dtype=float32)

y_pred_nn = (y_pred_nn > 0.5)

output:
array([[False],
       [False],
       [False],
       ...,
       [False],
       [False],
       [False]])

预期结果:

array([[0],
       [0],
       [0],
       ...,
       [0],
       [0],
       [0]], dtype=float32)
# just convert to floats then
y_pred_nn = (y_pred_nn > 0.5).astype(np.float32)