读书报告
读书报告
Python科学计算四大库应用实践
numpy scipy pandas matplotlib
一、基本函数用法(10分)
NumPy核心功能
import numpy as np
创建数组
arr = np.array([1, 2, 3])
常用函数
print(np.linspace(0, 10, 5)) # 线性间隔数组
print(np.random.normal(0, 1, 10)) # 正态分布随机数
Pandas数据处理
import pandas as pd
创建DataFrame
df = pd.DataFrame({'A': [1, 2], 'B': ['x', 'y']})
数据操作
print(df.groupby('B').mean()) # 分组聚合
SciPy科学计算
from scipy import optimize
解方程
result = optimize.root(lambda x: x2 - 4, x0=3)
print(result.x) # 输出: [2.]
Matplotlib绘图
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [4, 5, 6], 'r--')
plt.xlabel('X轴') # 坐标轴标签
plt.show()
二、具体问题求解(10分)
题目:用最小二乘法拟合二次函数
生成带噪声的数据
= np.linspace(0, 10, 20)
= 1.5 x*2 + np.random.normal(0, 5, 20)
SciPy拟合
params, _ = optimize.curve_fit(lambda x, a: ax*2, x, y)
print(f"拟合系数: {params[0]:.2f}") # 输出接近1.5
三、图像处理实战(10分)
图像卷积滤波(SciPy)
from scipy.ndimage import convolve
import matplotlib.image as mpimg
读取图像并应用边缘检测核
img = mpimg.imread('test.jpg')[..., 0] # 取灰度通道
kernel = np.array([[-1,-1,-1], [-1,8,-1], [-1,-1,-1]])
edges = convolve(img, kernel)
plt.imshow(edges, cmap='gray')
图像直方图均衡化(NumPy+Matplotlib)
计算直方图
hist, bins = np.histogram(img.flatten(), 256, [0,256])
cdf = hist.cumsum()
cdf_normalized = cdf * hist.max() / cdf.max()
plt.plot(cdf_normalized, color='b')

浙公网安备 33010602011771号