1.scipy Intro
title: "SciPy-数值计算库" date: 2026-05-24T14:11:00Z
1import numpy as np
2import pylab as pl
1import matplotlib as mpl
2mpl.rcParams['font.sans-serif'] = ['SimHei']
SciPy-数值计算库
1import scipy
2scipy.__version__
'1.0.0'
常数和特殊函数
1from scipy import constants as C
2print (C.c) # 真空中的光速
3print (C.h) # 普朗克常数
299792458.0
6.62607004e-34
1C.physical_constants["electron mass"]
(9.10938356e-31, 'kg', 1.1e-38)
1# 1英里等于多少米, 1英寸等于多少米, 1克等于多少千克, 1磅等于多少千克
2print(C.mile)
3print(C.inch)
4print(C.gram)
5print(C.pound)
1609.3439999999998
0.0254
0.001
0.45359236999999997
1import scipy.special as S
1print (1 + 1e-20)
2print (np.log(1+1e-20))
3print (S.log1p(1e-20))
1.0
0.0
1e-20
1m = np.linspace(0.1, 0.9, 4)
2u = np.linspace(-10, 10, 200)
3results = S.ellipj(u[:, None], m[None, :])
4
5print([y.shape for y in results])
[(200, 4), (200, 4), (200, 4), (200, 4)]
1#%figonly=使用广播计算得到的`ellipj()`返回值
2fig, axes = pl.subplots(2, 2, figsize=(12, 4))
3labels = ["$sn$", "$cn$", "$dn$", "$\phi$"]
4for ax, y, label in zip(axes.ravel(), results, labels):
5 ax.plot(u, y)
6 ax.set_ylabel(label)
7 ax.margins(0, 0.1)
8
9axes[1, 1].legend(["$m={:g}$".format(m_) for m_ in m], loc="best", ncol=2);