【问题标题】:how to reset every value in a 2d numpy array to either 0, or the max value in the array?如何将 2d numpy 数组中的每个值重置为 0 或数组中的最大值?
【发布时间】:2019-07-07 15:48:32
【问题描述】:

我有一个 2d numpy 数组,其中填充了许多整数,例如:从 0 到 9。如何有效地将任何小于 9 的值重置为 0,只留下 9?

最大值不会总是为 9,因此在解析之前需要使用np.amax(array) 或类似的方法来定义最大值。

【问题讨论】:

标签: python python-3.x python-2.7 numpy


【解决方案1】:

array[array < 9] = 0 解决了这个问题,感谢@Masoud

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-07-30
    • 1970-01-01
    • 2017-10-13
    • 1970-01-01
    • 1970-01-01
    • 2020-03-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多