if <条件>:
语句
elif<条件>:
语句
else:
语句
for a in b:
语句
else:
语句
berak continue pass break
def 函数名(参数):
语句 \
return a
a<b and b>c
数值计算库:numpy+scipy(Fortran数值计算库)=matlab
符号计算库:sympy
绘图及可视化: matplotlib
a[起始:终点:步长]
import numpy as np persontype = np.dtype({ 'names':['name', 'age', 'weight'], 'formats':['S32','i', 'f']}) a = np.array([("Zhang",32,75.5),("Wang",24,65.2)], dtype=persontype) + - * / //整除 ** power % 求余 def triangle_wave(x, c, c0, hc): x = x - int(x) # 三角波的周期为1,因此只取x坐标的小数部分进行计算 if x >= c: r = 0.0 elif x < c0: r = x / c0 * hc else: r = (c-x) / (c-c0) * hc return r x = np.linspace(0, 2, 1000) y = np.array([triangle_wave(t, 0.6, 0.4, 1.0) for t in x]) len(a) a.shape >>> a = np.arange(12).reshape(2,3,2) >>> b = np.arange(12,24).reshape(2,2,3) >>> c = np.dot(a,b) >>> np.save("a.npy", a) >>> c = np.load( "a.npy" ) >>> c array([[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10, 11]]) from scipy.optimize import fsolve 2 from math import sin,cos 3 4 def f(x): 5 x0 = float(x[0]) 6 x1 = float(x[1]) 7 x2 = float(x[2]) 8 return [ 9 5*x1+3, 10 4*x0*x0 - 2*sin(x1*x2), 11 x1*x2 - 1.5 12 ] >>> import matplotlib.pyplot as plt >>> fig = plt.figure() >>> ax = fig.add_axes([0.15, 0.1, 0.7, 0.3]) >>> fig = plt.figure() >>> fig.show() >>> fig.patch.set_color("g") >>> fig.canvas.draw() result = fsolve(f, [1,1,1]) print result print f(result)