小编GBA*_*A13的帖子

如何制作"可调用功能"

我目前正在编写一个名为f_from_data的python定义,它在一行上使用了插值查找点到目前为止我写的这个:

def f_from_data(xs, ys, x):
    xfine = np.linspace(min(xs), max(xs), 10000)
    y0 = inter.interp1d(xs, ys, kind = 'linear')
    ans = (y0(xfine))[numpy.searchsorted(xfine, x)]
    ans =  round(ans,2)
    return ans
Run Code Online (Sandbox Code Playgroud)

这给了我想要的东西,所以我可以输入:

f = f_from_data([3, 4, 6], [0, 1, 2])
print f(3)
>>>0.0
Run Code Online (Sandbox Code Playgroud)

我该怎么做呢?我环顾四周但似乎找不到任何东西,因为我觉得它真的很微不足道,但我只是想念一些东西.

python numpy callable

7
推荐指数
1
解决办法
1264
查看次数

用逗号分隔字符串列表

我想转换

['60,78', '70,77', '80,74', '90,75', '100,74', '110,75']
Run Code Online (Sandbox Code Playgroud)

进入

['60', '78', '70', '77'.. etc]
Run Code Online (Sandbox Code Playgroud)

我以为我可以用

for word in lines:
    word = word.split(",")
    newlist.append(word)
return newlist
Run Code Online (Sandbox Code Playgroud)

但这会产生以下结果:

[['60', '78'], ['70', '77'], ['80', '74'], ['90', '75'], ['100', '74'], ['110', '75']]
Run Code Online (Sandbox Code Playgroud)

谁能提供解决方案?

python string list

1
推荐指数
2
解决办法
1万
查看次数

标签 统计

python ×2

callable ×1

list ×1

numpy ×1

string ×1