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()
本文介绍了如何使用NumPy进行数组操作及统计分析,并通过Matplotlib实现数据可视化,包括折线图、散点图和直方图的绘制。
2296

被折叠的 条评论
为什么被折叠?



