Anu*_*han 3 python numpy list attributeerror python-3.7
time_weight = list(100*np.exp(np.linspace(-1/divisor, -(num_steps-1)/divisor, num_steps))).apply(lambda x:int(x))
Run Code Online (Sandbox Code Playgroud)
当我尝试这样做时,我在 Python 3.7 中收到以下错误。
AttributeError:“列表”对象没有属性“应用”
有人能帮忙吗?
小智 5
正如错误所述,list类型没有apply属性。这就是说,如果您有一个列表l并且想要设置int为其中的每个元素键入,您可以使用:
l = [int(x) for x in l]
Run Code Online (Sandbox Code Playgroud)
或者
l = list(map(int,l))
Run Code Online (Sandbox Code Playgroud)