【问题标题】:Replacing numpy array with max value [duplicate]用最大值替换numpy数组[重复]
【发布时间】:2021-07-06 12:09:23
【问题描述】:

我有一个数组,

a = np.array([[0,9,8],[5,6,4]])

如何将轴1中的每个数组替换为其数组的最大值?

除了输出-a = np.array([9,6]),其中 9 是 [0,9,8] 中的最大值,6 是 [5,6,4] 中的最大值

谢谢

【问题讨论】:

  • a.max(axis=1)

标签: python numpy


【解决方案1】:

你应该使用

np.max(a, axis=1)

Link to documentation

【讨论】:

    【解决方案2】:

    你可以这样做的另一个实现

    np.array([max(i) for i in a])
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-02-16
      • 2019-02-02
      • 2018-03-30
      • 1970-01-01
      • 1970-01-01
      • 2018-07-12
      • 1970-01-01
      相关资源
      最近更新 更多