现有一个数组A, 如何快速让A中大于5的元素值变为999? 方法如下:
a = np.arange(12).reshape(3, 4)
b = np.where(a > 5)
a[b] = 999
print(a)
结果为:
[[ 0 1 2 3]
[ 4 5 999 999]
[999 999 999 999]]
现有一个数组A, 如何快速让A中大于5的元素值变为999? 方法如下:
a = np.arange(12).reshape(3, 4)
b = np.where(a > 5)
a[b] = 999
print(a)
结果为:
[[ 0 1 2 3]
[ 4 5 999 999]
[999 999 999 999]]