from numpy import*
t=array([52,45,43,32])
s=array([1.62,1.60,1.61,1.46])
z=t/s**2
print(z)
[19.81405274 17.578125 16.58886617 15.01219741]
from numpy import*
a=zeros(3)
print(a)
b=ones(4)
print(b)
c=arange(5)
print(c)
[0. 0. 0.] [1. 1. 1. 1.] [0 1 2 3 4]
from numpy import*
a=loadtxt("test.txt")
b=a.sum(1)
print(b)
savetxt("总分.txt",b,fmt='%.2f')
[ 6. 1. 5. 5. 7. 1. 7. 49. 2. 10. 15. 12. 3. 10. 8. 48. 1. 92.]
b.shape=(18,1)
c=hstack((a,b))
savetxt("总分2.txt",c,fmt='%.2f',delimiter='\t')
from matplotlib.pyplot import*
a=[1,4,5,5]
pie(a)
show()
from matplotlib.pyplot import*
a=[1,4,5,5]
rcParams['font.sans-serif']=['SimHei']
labels=['不及格','及格','良好','优秀']
colors=['red','blue','yellow','green']
pie(a,colors=colors,labels=labels)
title('学生体质健康分布图')
show()
import numpy
a=numpy.loadtxt("test.txt")
from matplotlib.pyplot import*
plot(a)
rcParams['font.sans-serif']=['SimHei']
legend(labels=['金牌','银牌','铜牌'])
colors=['red','blue','yellow','green']
title('奖牌图')
show()
from matplotlib.pyplot import*
bar(['2017','2018','2019'],['890','1130','1289'],width=0.5)
show()