numpy的总结
一:基础篇
1)数值
import numpy as np np.set_printoptions(linewidth=200,suppress=True) a = np.array([1,2,3,4,5,6,7,8],dtype=np.int) print(a) print(a.shape) c = np.reshape(a,[4,-1]) print(c) d = np.asarray(a,np.float) print(d)
# 取4个值: b = np.linspace(1,10,4,dtype=np.int) print(b)
# 每4步取一值
b = np.arange(1,10,4,dtype=np.float)
print(b)
#对比两种方式
#1)改变g会改变a的值 a = np.arange(10) g = a[1:] print(g) g[1]=5 print(g) print(a) 2)改变g不会改变a的值 h = b[a] print(h) h[1] = 7 print(h) print(b)
2)数据类型转换
s='caixuwu小裁缝' f = np.fromstring(s,dtype=np.int8) print(f) z = np.fromiter('123456789',dtype=np.int,count=3) print(z)
二:计算篇
e = np.logspace(1,4,4,endpoint=True,base=10,dtype=np.int) print(e)