python学习笔记01

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)

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值