python赋值nan

**

python赋值nan

**
1.
import numpy as np
t = np.arange(24).reshape(4,6)
t[1,3:] = np.nan
print(t)
print(type(t[1,1]))
输出结果:
[[ 0 1 2 3 4 5]
[ 6 7 8 -2147483648 -2147483648 -2147483648]
[ 12 13 14 15 16 17]
[ 18 19 20 21 22 23]]

2.
import numpy as np
t = np.arange(24,dtype = float).reshape(4,6)
#t = np.arange(24).reshape(4,6).astype(float)
t[1,3:] = np.nan
print(t)
print(type(t[1,1]))
输出结果:
[[ 0. 1. 2. 3. 4. 5.]
[ 6. 7. 8. nan nan nan]
[12. 13. 14. 15. 16. 17.]
[18. 19. 20. 21. 22. 23.]]

总结:
-2147483648是32位系统里int类型的下界
np.nan是浮点数,而arange生成的array里是整数。

你可能感兴趣的:(python赋值nan)