python - 使用 Python numpy where 条件将整体更改为低于特定值

标签 python arrays numpy where-clause

这是我的数组:

import numpy as np
a = np.array([0, 5.0, 0, 5.0, 5.0])

是否有可能以某种方式使用 numpy.where 将值 x 添加到 a 中小于

所以像这样:

a = a[np.where(a < 5).add(2.5)]

应该返回:

array([2.5, 5.0, 2.5, 5.0, 5.0])

最佳答案

a = np.array([0., 5., 0., 5., 5.])
a[np.where(a < 5)] += 2.5

如果你真的想使用where或者只是

a[a < 5] += 2.5

我通常将其用于此类操作。

关于python - 使用 Python numpy where 条件将整体更改为低于特定值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41463049/

相关文章:

双端队列上的 Python 标准差

python - 使用 SWIG Controller 将 python 中的 numpy 函数传递给 C++

python - Numpy 调整大小并填充特定值

python - flask : 'Token' object has no attribute 'test' | render_template error

python - 在本地 gpu 和 colab gpu 上进行分布式训练

python - 分层注意力网络 - model.fit 生成错误 'ValueError: Input dimension mis-match'

从 requirements.txt 安装 python pip 问题

c++ - 有人可以解释这个 C++ 符号吗?

c - C中的数组问题

PHP 数组键值