Numpy学习笔记(三)
写点笔记
共 2397字,需浏览 5分钟
·
2021-07-08 16:51
tian=np.linspace(-10,10,20)
print(tian)
tian=np.abs(tian)
print(tian)
tian=np.linspace(1,3,3)
tian=tian*tian
print(tian)
print(np.sqrt(tian))
tian=np.square(tian)
print(tian)
tian=np.arange(1,10,1)
print(tian)
print(np.log10(tian))
tian=np.rint(tian)
print(tian)
tian=np.arange(1,3,1)
tian=np.exp(tian)
print(tian)
tian=np.linspace(-1,5,6)
print(np.sign(tian))
tian=np.linspace(-1,5,6)
zhang=np.linspace(2,6,6)
print(np.sign(tian))
print(np.maximum(tian,zhang))
tian=np.arange(1,100,1)
#参数这里的tianjingle.txt是文件名称
#fmt元素的格式,%d表示整数,%.2f表示浮点数保留两位小数
np.savetxt('tianjingle.txt',tian,fmt="%d",delimiter=",")
tian=np.loadtxt("tianjingle.txt",dtype=np.int64,delimiter=",",unpack=False)
print(tian)
#平均值
print(np.mean(tian))
#加权平均值
print(np.average(tian))
#标准差
print(np.std(tian))
#计算方差
print(np.var(tian))
#最大值与最小值的差
print(np.ptp(tian))
#中位数
print(np.median(tian))
print(np.gradient(tian))
file="C:\\Users\\Administrator\\Desktop\\新建文件夹\\IMG_20201002_161629.jpg"
tian=np.array(Image.open(file).convert('L'))
tian=tian.astype(np.int8)
image=Image.fromarray(tian)
image.save("tianj.png")
im=Image.open("tianj.png")
im.show()
评论