标签:语句 01 python 笔记 fig np import c0 x1
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)
标签:语句,01,python,笔记,fig,np,import,c0,x1 来源: https://blog.csdn.net/JISANSAN/article/details/117886435
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。