【问题标题】:Removing a row that contains a negative float in a numpy aray在 numpy 数组中删除包含负浮点数的行
【发布时间】:2022-01-07 10:01:21
【问题描述】:

我有一个由 3 列组成的 numpy 数组,并且一列中有一个值为负值。我需要删除包含此值的整行,因为它对应于异常结果。

numpy 数组看起来有点像这样:

[[98.4, 0.236, 0.0925]

 [95.2, -0.162, 0.0625]

 [92.3, 0.112, 0.0526]]

我将如何删除包含负值的整行?

【问题讨论】:

    标签: python numpy negative-number


    【解决方案1】:

    您可以使用布尔掩码进行索引:

    result = array[(array >= 0).all(axis=1)]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-22
      • 1970-01-01
      相关资源
      最近更新 更多