读书报告

  1. 报告框架搭建
  • 封面:写上读书报告标题(如“关于numpy、scipy、pandas、matplotlib的读书报告”)、作者姓名、日期等基本信息。
  • 目录:列出报告各部分内容及对应页码,方便阅读。
  1. numpy部分
  • 基本函数用法:介绍numpy的核心数据结构 ndarray ,如创建一维数组 import numpy as np; arr = np.array([1, 2, 3])  ,二维数组 arr_2d = np.array([[1, 2], [3, 4]]) 。讲解常用函数,像 np.sum(arr) 用于计算数组元素总和, np.mean(arr) 计算平均值, np.reshape(arr_2d, (4,)) 进行数组形状变换等。阐述numpy广播机制,例如不同形状数组间运算的规则。
  • 解决具体问题示例:以书本上用数值方法求解方程为例,如用numpy实现二分法求解方程 x**2 - 4 = 0  。定义函数 def bisection_method(): a, b = 0, 5 tol = 1e - 6 while (b - a) > tol: c = (a + b) / 2 if np.sign(np.power(c, 2) - 4) == np.sign(np.power(a, 2) - 4): a = c else: b = c return (a + b) / 2  ,通过具体代码展示numpy在数值计算中的应用。
  1. scipy部分
  • 基本函数用法:介绍scipy在科学计算各领域的功能模块,如 scipy.integrate 用于数值积分, from scipy.integrate import quad; result, error = quad(lambda x: x2, 0, 1) 计算定积分\int_{0}^{1} x^{2}dx 。 scipy.optimize 用于优化问题求解,如 from scipy.optimize import minimize; def objective(x): return x[0]2 + x[1]**2; x0 = np.array([1, 1]); res = minimize(objective, x0) 求解函数最小值。
  • 解决具体问题示例:若书本有振动系统相关问题,利用 scipy.signal 分析信号,如模拟一个简谐振动信号 import matplotlib.pyplot as plt; t = np.linspace(0, 10, 1000); y = np.sin(2 * np.pi * 0.5 * t); plt.plot(t, y)  ,再用 scipy.signal.find_peaks(y) 寻找信号峰值,展示scipy在信号处理等实际问题中的应用。
  1. pandas部分
  • 基本函数用法:介绍pandas的 Series 和 DataFrame 数据结构。创建 Series 对象 import pandas as pd; s = pd.Series([1, 2, 3], index=['a', 'b', 'c'])  , DataFrame 对象 df = pd.DataFrame({'col1': [1, 2, 3], 'col2': ['a', 'b', 'c']})  。讲解数据读取函数如 pd.read_csv('data.csv') 读取CSV文件,数据清洗函数如 df.dropna() 删除缺失值, df.duplicated().sum() 查看重复值等。
  • 解决具体问题示例:假设书本有学生成绩分析问题,用 pandas 读取成绩数据文件,计算各学科平均分 df.mean()  ,统计不同分数段人数 df['score'].groupby(pd.cut(df['score'], bins=[0, 60, 70, 80, 90, 100])).count()  ,展示pandas在数据分析中的应用。
  1. matplotlib部分
  • 基本函数用法:介绍绘图基础函数,如 import matplotlib.pyplot as plt; plt.plot([1, 2, 3], [4, 5, 6]) 绘制折线图, plt.scatter([1, 2, 3], [4, 5, 6]) 绘制散点图,设置图表标题 plt.title('My Plot')  ,坐标轴标签 plt.xlabel('X - axis'), plt.ylabel('Y - axis') 等。讲解子图绘制 fig, axs = plt.subplots(2, 1); axs[0].plot([1, 2, 3], [4, 5, 6]); axs[1].scatter([1, 2, 3], [4, 5, 6])  。
  • 解决具体问题示例:若书本有数据可视化相关题目,比如展示不同产品销售趋势,读取销售数据后用 matplotlib 绘制折线图展示各产品随时间的销售变化,通过设置颜色、线条样式等使图表更美观,直观呈现数据特点。
  1. 图像处理部分
  • 利用 matplotlib.image 模块进行简单图像处理。如读取图像 import matplotlib.image as mpimg; img = mpimg.imread('image.jpg')  ,显示图像 plt.imshow(img)  。介绍图像灰度化处理 gray_img = np.dot(img[..., :3], [0.299, 0.587, 0.114])  ,展示处理前后图像对比。也可借助 scipy.ndimage 进行图像滤波等操作,如 from scipy.ndimage import gaussian_filter; filtered_img = gaussian_filter(img, sigma = 1) 对图像进行高斯滤波,减少噪声,通过代码展示图像说明图像处理过程。
posted @ 2025-06-29 21:28  不要命的蛋  阅读(16)  评论(0)    收藏  举报