小编JY0*_*078的帖子

Python 使用 curve_fit 拟合对数函数

我正在尝试使用 拟合对数曲线curve_fit,假设它遵循Y=a*ln(X)+b,但拟合的数据看起来仍然不正确。

现在我正在使用以下代码:

from scipy.optimize import curve_fit
X=[3.0, 3.1, 3.2, 3.3, 3.4, 3.5, 3.6, 3.7, 3.8, 3.9, 4.0, 4.1, 4.2, 4.3, 4.4,
   4.5, 4.6, 4.7]
Y=[-5.890486683, -3.87063815, -2.733484754, -2.104972457, -1.728190699, 
   -1.477976987, -1.285589215, -1.120224363, -0.968576581, -0.82492453, 
   -0.688457731, -0.559780327, -0.440437932, -0.331886009, -0.235162505, 
   -0.150572236, -0.078157925, -0.01718885]

#plot Y against X
fig = plt.figure(num=None, figsize=(9, 7),facecolor='w', edgecolor='k')
ax2=fig.add_subplot(111)
ax2.scatter(X,Y)

#fit using curve_fit
popt, pcov = curve_fit(Hyp_func, X, Y,maxfev=10000)
print(' fit coefficients:\n', popt)
#fit coefficients:
#[9.51543579 -14.10114674]

#plot Y_estimated against X …
Run Code Online (Sandbox Code Playgroud)

python numpy logarithm matplotlib curve-fitting

5
推荐指数
1
解决办法
4601
查看次数

从给定列表生成所有可能的 k-mers(字符串组合)

我有一个S由 20 个字符组成的字符串:

S='ARNDCEQGHILKMFPSTWYV'
Run Code Online (Sandbox Code Playgroud)

我需要从给定的输入 k 生成所有可能的 k-mer 组合。

当 时k == 3,则有 8000 个组合 ( 20*20*20),输出列表如下所示:

output = ['AAA', 'AAR', ..., 'AVV', ..., 'VVV'] #len(output)=8000
Run Code Online (Sandbox Code Playgroud)

当 时k == 2,则有 400 种组合 ( 20*20),输出列表如下所示:

output = ['AA', 'AR', 'AN', ..., 'VV'] #len(output)=400
Run Code Online (Sandbox Code Playgroud)

k == 1,那么只有 20 种组合:

output =['A', 'R', 'N', ..., 'Y', 'V'] #len(output)=20
Run Code Online (Sandbox Code Playgroud)

如果数字k是固定的,我知道该怎么做,比如 if k == 3,那么我可以这样做:

for a in S:
   for b in …
Run Code Online (Sandbox Code Playgroud)

python string combinations list permutation

3
推荐指数
1
解决办法
2597
查看次数