Enly

导航

读书报告

#numpy

1.基本函数的用法:

 1 import numpy as np
 2 
 3 a = np.ones((4,5))
 4 print(a)
 5 print("\n")
 6 print(a.ndim)
 7 print(a.shape)
 8 print(a.dtype)
 9 print("\n")
10 b = np.random.rand(5,3)
11 print(b[2])
12 print(b[1:3])

运行结果:

2.具体问题:

1 #2 如何对ndarray的每个变量求平方根
2 import numpy as np
3 a = np.array([1, 4, 9, 16, 25])
4 result = np.sqrt(a)
5 print(result)

运行结果:

3.图像处理:

 1 from PIL import Image
 2 import numpy as np
 3 vec_el = np.pi/2.2
 4 vec_az = np.pi/4.
 5 depth = 10.
 6 im = Image.open('D:/学习/个人/pythonwork/textbook/gif/picframe00.png').convert('L')
 7 a = np.asarray(im).astype('float')
 8 grad = np.gradient(a)
 9 grad_x, grad_y = grad
10 grad_x = grad_x*depth/100.
11 gead_y = grad_y*depth/100.
12 dx = np.cos(vec_el)*np.cos(vec_az)
13 dy = np.cos(vec_el)*np.sin(vec_az)
14 dz = np.sin(vec_el)
15 A = np.sqrt(grad_x**2 + grad_y**2 + 1.)
16 uni_x = grad_x/A
17 uni_y = grad_y/A
18 uni_z = 1./A
19 a2 = 255*(dx*uni_x + dy*uni_y + dz*uni_z)
20 a2 = a2.clip(0,255)
21 im2 =  Image.fromarray(a2.astype('uint8'))
22 im2.save('D:/学习/个人/pythonwork/textbook/gif/HandDraw.jpg')

原图:

 

运行结果:

 

 

#scipy

1.基本函数的用法:

1 from scipy import constants
2 
3 print(constants.pi)
4 print(constants.golden)

运行结果:

2.具体问题:

3.图像处理:

1 from matplotlib import pyplot as plt
2 
3 #  使用Matplotlib进行图像处理
4 img=plt.imread('picframe00.png')
5 plt.imshow(img[::-1])  #  实现图片的垂直翻转翻转
6 #  plt.imshow([:,::-1])  #  实现图片的水平翻转
7 plt.savefig("picframe00_.png")  #  然后保存为其他图片

原图:

结果:

 

 

 

#pandas

1.基本函数的用法:

2.具体问题:

3.图像处理:

 

 

 

#matplotlib

1.基本函数的用法:

2.具体问题:

3.图像处理:

posted on 2023-12-27 10:11  Enly_321  阅读(6)  评论(0编辑  收藏  举报