<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Python on Chen Kai Blog</title><link>https://www.chenk.top/zh/tags/python/</link><description>Recent content in Python on Chen Kai Blog</description><generator>Hugo</generator><language>zh-CN</language><lastBuildDate>Mon, 15 Apr 2024 09:00:00 +0000</lastBuildDate><atom:link href="https://www.chenk.top/zh/tags/python/index.xml" rel="self" type="application/rss+xml"/><item><title>常微分方程（十八）：前沿专题与系列总结</title><link>https://www.chenk.top/zh/ode/18-%E5%89%8D%E6%B2%BF%E4%B8%93%E9%A2%98%E4%B8%8E%E6%80%BB%E7%BB%93/</link><pubDate>Mon, 15 Apr 2024 09:00:00 +0000</pubDate><guid>https://www.chenk.top/zh/ode/18-%E5%89%8D%E6%B2%BF%E4%B8%93%E9%A2%98%E4%B8%8E%E6%80%BB%E7%BB%93/</guid><description>&lt;p>&lt;strong>旅程到此结束：&lt;/strong> 十八章前，我们从一枚下落的苹果启程；今天，我们仍以同样的精神作结——继续将常微分方程（ODE）视为 &lt;em>变化的通用语言&lt;/em>，只是如今站在更高的山巅。&lt;/p></description></item><item><title>常微分方程（十七）：物理与工程应用</title><link>https://www.chenk.top/zh/ode/17-%E7%89%A9%E7%90%86%E4%B8%8E%E5%B7%A5%E7%A8%8B%E5%BA%94%E7%94%A8/</link><pubDate>Fri, 29 Mar 2024 09:00:00 +0000</pubDate><guid>https://www.chenk.top/zh/ode/17-%E7%89%A9%E7%90%86%E4%B8%8E%E5%B7%A5%E7%A8%8B%E5%BA%94%E7%94%A8/</guid><description>&lt;p>&lt;strong>微分方程绝非纯数学游戏——它正是理解物理世界的语言。&lt;/strong> 从天体运行到电路响应，从单摆摆动到桥缆后方的涡脱落，每一个动力系统都在用常微分方程（ODE）“说话”。&lt;/p></description></item><item><title>常微分方程（十六）：控制理论基础</title><link>https://www.chenk.top/zh/ode/16-%E6%8E%A7%E5%88%B6%E7%90%86%E8%AE%BA%E5%9F%BA%E7%A1%80/</link><pubDate>Tue, 12 Mar 2024 09:00:00 +0000</pubDate><guid>https://www.chenk.top/zh/ode/16-%E6%8E%A7%E5%88%B6%E7%90%86%E8%AE%BA%E5%9F%BA%E7%A1%80/</guid><description>&lt;p>&lt;strong>开车时，你不断根据车道位置调整方向；恒温器将室温与设定值比较后调节加热器；火箭通过摆动喷管微调推力矢量以保持箭体垂直。&lt;/strong> 抽掉硬件，核心思想始终如一：&lt;em>测量、比较、动作&lt;/em>。控制理论正是研究这一闭环过程的数学框架，而常微分方程（ODE）则是它的自然语言。&lt;/p></description></item><item><title>常微分方程（十五）：种群动力学</title><link>https://www.chenk.top/zh/ode/15-%E7%A7%8D%E7%BE%A4%E5%8A%A8%E5%8A%9B%E5%AD%A6/</link><pubDate>Sat, 24 Feb 2024 09:00:00 +0000</pubDate><guid>https://www.chenk.top/zh/ode/15-%E7%A7%8D%E7%BE%A4%E5%8A%A8%E5%8A%9B%E5%AD%A6/</guid><description>&lt;p>&lt;strong>为什么猞猁和雪兔的数量会以诡异的规律每 10 年循环一次？&lt;/strong> 为什么引入一个新物种有时会导致整个生态系统崩溃？为什么相似的竞争者有时能共存，有时却会相互灭绝？答案并不在物种本身，而在于描述这些物种之间关系的&lt;em>方程&lt;/em>。本章将带你梳理数学生态学中的经典模型：从单一种群的 Logistic 模型和 Allee 效应，到多物种间的竞争、捕食-被捕食振荡，再到年龄结构与空间扩散。&lt;/p></description></item><item><title>常微分方程（十四）：传染病模型与流行病学</title><link>https://www.chenk.top/zh/ode/14-%E4%BC%A0%E6%9F%93%E7%97%85%E6%A8%A1%E5%9E%8B%E4%B8%8E%E6%B5%81%E8%A1%8C%E7%97%85%E5%AD%A6/</link><pubDate>Wed, 07 Feb 2024 09:00:00 +0000</pubDate><guid>https://www.chenk.top/zh/ode/14-%E4%BC%A0%E6%9F%93%E7%97%85%E6%A8%A1%E5%9E%8B%E4%B8%8E%E6%B5%81%E8%A1%8C%E7%97%85%E5%AD%A6/</guid><description>&lt;p>2020 年初，全世界都在盯着一个由几个常微分方程组成的小系统做决策。“拉平曲线”并非一句口号，而是源于某个具体方程的直观体现；“群体免疫”也不是凭空猜测，而是通过一行公式推导出的阈值 &lt;span class="math-inline">$1 - 1/R_0$&lt;/span>
。Kermack 和 McKendrick 在 1927 年提出的 SIR 模型——仅四行数学表达式——竟精准到足以支撑万亿美元级别的政策抉择。&lt;/p></description></item><item><title>常微分方程（十三）：偏微分方程引论</title><link>https://www.chenk.top/zh/ode/13-%E5%81%8F%E5%BE%AE%E5%88%86%E6%96%B9%E7%A8%8B%E5%BC%95%E8%AE%BA/</link><pubDate>Sun, 21 Jan 2024 09:00:00 +0000</pubDate><guid>https://www.chenk.top/zh/ode/13-%E5%81%8F%E5%BE%AE%E5%88%86%E6%96%B9%E7%A8%8B%E5%BC%95%E8%AE%BA/</guid><description>&lt;p>&lt;strong>一旦某个量依赖于多个变量，常微分方程（ODE）的世界便会裂变为一个丰富得多的领域：偏微分方程（PDE）。&lt;/strong> 金属棒中的热量是位置与时间的函数；振动的弦在空间和时间中运动；静电势则存在于三维空间中。此时，ODE 的求解技巧不再是直接的答案，而成为构建解的工具——分离变量法将一个 PDE 转化为一族 ODE，这些 ODE 的本征值构成了相应算子的谱，而叠加原理则将所有部分重新缝合起来。&lt;/p></description></item><item><title>常微分方程（十二）：边值问题</title><link>https://www.chenk.top/zh/ode/12-%E8%BE%B9%E5%80%BC%E9%97%AE%E9%A2%98/</link><pubDate>Thu, 04 Jan 2024 09:00:00 +0000</pubDate><guid>https://www.chenk.top/zh/ode/12-%E8%BE%B9%E5%80%BC%E9%97%AE%E9%A2%98/</guid><description>&lt;p>初值问题给定起始状态，要求向前推进；边值问题则在两个不同位置提供部分信息，要求找出一条同时满足两端条件的解。措辞上只是微调，后果却大相径庭：边值问题可能有唯一解、无解，甚至无穷多解。它需要一套截然不同的工具箱——本质上是迭代的、全局的，并且与线性代数密不可分。&lt;/p></description></item><item><title>常微分方程（十一）：数值方法</title><link>https://www.chenk.top/zh/ode/11-%E6%95%B0%E5%80%BC%E6%96%B9%E6%B3%95/</link><pubDate>Mon, 18 Dec 2023 09:00:00 +0000</pubDate><guid>https://www.chenk.top/zh/ode/11-%E6%95%B0%E5%80%BC%E6%96%B9%E6%B3%95/</guid><description>&lt;p>科学和工程中，几乎所有有意思的微分方程都无法求得解析解。非线性向量场、变系数、成千上万个耦合的状态变量——纸笔在问题真正变得棘手之前就早已无能为力。数值积分是关键所在。本章将构建、评估并比较一小套算法，它们几乎能解决你遇到的任何常微分方程（ODE），同时还会提供诊断工具，帮你识别积分器何时在误导你。
&lt;figure class="article-figure">
 &lt;img src="https://blog-pic-ck.oss-cn-beijing.aliyuncs.com/posts/zh/ode/11-numerical-methods/illustration_1.png" alt="常微分方程（十一）：数值方法 — 章节概览图" loading="lazy" decoding="async" class="content-image">
 
&lt;/figure>
&lt;/p></description></item><item><title>常微分方程（十）：分岔理论</title><link>https://www.chenk.top/zh/ode/10-%E5%88%86%E5%B2%94%E7%90%86%E8%AE%BA/</link><pubDate>Fri, 01 Dec 2023 09:00:00 +0000</pubDate><guid>https://www.chenk.top/zh/ode/10-%E5%88%86%E5%B2%94%E7%90%86%E8%AE%BA/</guid><description>&lt;p>湖泊清澈几十年，一个夏天却突然变浑；电网平稳运行，几秒内却级联崩溃；钢柱在递增载荷下笔直挺立，直到突然弯折。&lt;/p>
&lt;p>这不是预测失败，而是动力系统遵循&lt;strong>分岔理论&lt;/strong>所刻画的固有规律：当参数越过临界值，相空间的拓扑结构发生突变，原本不可能的状态变为必然出现。本章的目标是分类这些“重排”，结果发现，范式屈指可数，掌握其特征后便能在各类系统中辨识它们。
&lt;figure class="article-figure">
 &lt;img src="https://blog-pic-ck.oss-cn-beijing.aliyuncs.com/posts/zh/ode/10-bifurcation-theory/illustration_1.png" alt="常微分方程（十）：分岔理论 — 章节概览图" loading="lazy" decoding="async" class="content-image">
 
&lt;/figure>
&lt;/p></description></item><item><title>常微分方程（一）：微分方程的起源与直觉</title><link>https://www.chenk.top/zh/ode/01-%E5%BE%AE%E5%88%86%E6%96%B9%E7%A8%8B%E7%9A%84%E8%B5%B7%E6%BA%90%E4%B8%8E%E7%9B%B4%E8%A7%89/</link><pubDate>Sat, 01 Jul 2023 09:00:00 +0000</pubDate><guid>https://www.chenk.top/zh/ode/01-%E5%BE%AE%E5%88%86%E6%96%B9%E7%A8%8B%E7%9A%84%E8%B5%B7%E6%BA%90%E4%B8%8E%E7%9B%B4%E8%A7%89/</guid><description>&lt;p>&lt;strong>你身边的一切都在变化：&lt;/strong> 咖啡会凉，人口会涨，单摆会摆，病毒会传，股价会震荡，行星会绕行。这些系统都无法用“某物等于多少”来描述，而只能用“某物变化得多快”来刻画。这种描述方式正是微分方程的用武之地——学会读懂它，就等于学会了阅读物理与生物学所使用的语言。&lt;/p></description></item><item><title>Python 工程实践（八）：性能优化 —— 性能分析、缓存与适时收手</title><link>https://www.chenk.top/zh/python-engineering/08-performance-and-profiling/</link><pubDate>Wed, 27 Apr 2022 09:00:00 +0000</pubDate><guid>https://www.chenk.top/zh/python-engineering/08-performance-and-profiling/</guid><description>&lt;p>Donald Knuth 那句广为流传的名言常被断章取义。完整原文是：“我们应当忽略微小的效率提升，比如 97% 的情况：过早优化是一切罪恶之源。然而，我们也不应放过那至关重要的 3% 中的良机。”后半句恰恰是重点所在——性能优化并非追求“一切皆快”，而是精准识别真正影响全局的那 3%，并集中资源将其优化。&lt;/p></description></item><item><title>Python 工程实践（七）：打包分发 —— 从 pip install 到 PyPI</title><link>https://www.chenk.top/zh/python-engineering/07-packaging-and-distribution/</link><pubDate>Sun, 24 Apr 2022 09:00:00 +0000</pubDate><guid>https://www.chenk.top/zh/python-engineering/07-packaging-and-distribution/</guid><description>&lt;p>你写了一个实用的小工具，同事找你要。你把文件夹打包成 ZIP 发过去，对方解压后运行 &lt;code>python main.py&lt;/code>，却报了 &lt;code>ModuleNotFoundError&lt;/code> —— 因为缺少依赖。他手动装上依赖，结果版本不对；更糟的是，他用的是 Python 3.8，而你的代码里用了 f-string 中的海象运算符（walrus operator），这在 3.8 里根本跑不了。&lt;/p></description></item><item><title>Python 工程实践（六）：并发编程 —— 线程、进程与 asyncio</title><link>https://www.chenk.top/zh/python-engineering/06-concurrency/</link><pubDate>Thu, 21 Apr 2022 09:00:00 +0000</pubDate><guid>https://www.chenk.top/zh/python-engineering/06-concurrency/</guid><description>&lt;p>你的脚本一次只下载 100 个文件，每个约耗时 2 秒——绝大部分时间在等待服务器响应，总耗时 200 秒，而 CPU 99% 的时间处于空闲状态。你为网络延迟付费，却白白浪费了计算资源，并发编程正是为了解决这个问题而诞生的。&lt;/p></description></item><item><title>Python 工程实践（五）：I/O、序列化与数据格式</title><link>https://www.chenk.top/zh/python-engineering/05-io-and-serialization/</link><pubDate>Tue, 19 Apr 2022 09:00:00 +0000</pubDate><guid>https://www.chenk.top/zh/python-engineering/05-io-and-serialization/</guid><description>&lt;p>大多数程序本质上只是在不同数据格式之间搭管道：读一个 CSV，转换一下，写成 JSON；加载配置文件，校验后传给应用。每个 Python 开发者都写过这类代码，而其中大多数人至少踩过一次编码、路径处理或序列化细节的坑。&lt;/p></description></item><item><title>Python 工程实践（四）：类型提示、代码检查与质量保障</title><link>https://www.chenk.top/zh/python-engineering/04-type-hints-and-linting/</link><pubDate>Sun, 17 Apr 2022 09:00:00 +0000</pubDate><guid>https://www.chenk.top/zh/python-engineering/04-type-hints-and-linting/</guid><description>&lt;p>代码评审应聚焦于逻辑与架构设计，而不是纠结于单引号还是双引号——这类争论纯粹是浪费工程师的时间。解决方案很简单：让机器处理代码风格，让人专注于逻辑正确性。&lt;/p></description></item><item><title>Python 工程实践（三）：测试——pytest、Fixture 与信心循环</title><link>https://www.chenk.top/zh/python-engineering/03-testing-and-debugging/</link><pubDate>Thu, 14 Apr 2022 09:00:00 +0000</pubDate><guid>https://www.chenk.top/zh/python-engineering/03-testing-and-debugging/</guid><description>&lt;p>你只改了一行代码，却导致三个毫不相干的功能崩溃；重构一个函数后，不得不花上两小时手动点击整个应用，只为确认一切是否还正常；周五部署上线，结果半夜就被报警电话叫醒……所有这些，都是同一种病的症状：&lt;strong>没有测试&lt;/strong>。&lt;/p></description></item><item><title>Python 工程实践（二）：项目结构 —— 从脚本到包</title><link>https://www.chenk.top/zh/python-engineering/02-project-structure/</link><pubDate>Tue, 12 Apr 2022 09:00:00 +0000</pubDate><guid>https://www.chenk.top/zh/python-engineering/02-project-structure/</guid><description>&lt;p>每个项目都始于单个文件。你写下 &lt;code>main.py&lt;/code>，它能运行；接着不断添加功能，直到某天猛然发现：这个文件已经膨胀到 1500 行，函数层层嵌套，彼此调用，而它们依赖的全局变量却定义在 800 行开外。代码虽然能跑，但没人（包括未来的你）看得懂。&lt;/p></description></item><item><title>Python 工程实践（一）：环境搭建——pyenv、venv 与依赖地狱</title><link>https://www.chenk.top/zh/python-engineering/01-environment-and-toolchain/</link><pubDate>Sun, 10 Apr 2022 09:00:00 +0000</pubDate><guid>https://www.chenk.top/zh/python-engineering/01-environment-and-toolchain/</guid><description>&lt;p>每位 Python 开发者都经历过这样的时刻：你在同事的机器上运行一段脚本，结果却崩溃了——因为对方用的是 Python 3.8，而你是在 3.11 上写的。更糟的是，你执行了 &lt;code>pip install&lt;/code> 全局安装某个包，结果意外破坏了一个完全无关的项目。Python 的环境管理体系一旦掌握，其实非常强大，但默认体验却像一片布满地雷的雷区。&lt;/p></description></item></channel></rss>