numpy过滤
np.where 返回的是索引
import numpy as np
x = np.arange(9.).reshape(3, 3)
/*
[[0. 1. 2.]
[3. 4. 5.]
[6. 7. 8.]]
*/
y = np.where(x > 3)
/*
(array([1, 1, 2, 2, 2]), array([1, 2, 0, 1, 2]))
(1 1) (1 2) (2 0) (2 1) (2 2)这些位置的值都大于3
*/
#############输出大于3
print (x[y])
######记得在y的前面加上[] 不然会报错
修改numpy里面的数字
import numpy as np
x = np.arange(9.).reshape(3, 3)
#############让大于3的元素都等于10
x[x>3]=10
print(x)