数据结构
函数
常用库
pandas
dataframe
scipy.optimize
minimize
https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.minimize.html
def minimize(fun, x0, args=(), method=None, jac=None, hess=None,
hessp=None, bounds=None, constraints=(), tol=None,
callback=None, options=None):
fun: 目标函数(最小化结果) func(x, *args) -> float
x为一维的变量向量
x0: 初始猜测解;
错误和异常
异常处理
type/except
try:
x=int(input("input an num: "))
break
except ValueError:
print("is not num, please try again")
IO
文件读取
读文件
https://blog.csdn.net/xrinosvip/article/details/82019844
f = open('filename', 'r')
fileInfo=f.read()
f.close()
with open(desc_file) as content:
dict_desc_info = yaml.load(content)
# 按行读取
for line in f.readlines():
print(line.strip())
写文件
f = open('filename', 'w')
f.write('hello, python!')
f.close()
with open('filename', 'w') as f:
f.write('hello, python!')