1.numpy array是list一个很好的补充,numpy array可以进行数组的整体操作。
a=np.array([1,2,3,4,5])
b=np.array([1,2,3,4,5])
c=a/b
2.numpy构造数组子集的操作很方便,并进行数据统计。
import numpy as np
height = np.round(np.random.normal(1.75,0.20,5000),2)
weight = np.round(np.random.normal(60.32,15,5000),2)
np_city=np.column_stack((height,weight))
np.mean(np_city[:,0])
np.median(np_city[:,0])
np.corrcoef(np_city[:,0],np_city[:,1])
np.std(np_city[:,0])
3. matplotlib折线图、散点图、直方图的使用
import matplotlib.pyplot as plt
year=[1950,1970,1990,2010]
pop=[2.519,3.692,5.263,6.972]
plt.plot(year,pop)
plt.scatter(year,pop)
values=[0,0.3,1.2,3,4,5,4,7,30,23,34]
plt.hist(values,bins=3)
plt.show()