【问题标题】:Attribute Error: list object has no attribute 'apply'属性错误:列表对象没有属性“应用”
【发布时间】:2020-05-07 10:35:40
【问题描述】:
time_weight = list(100*np.exp(np.linspace(-1/divisor, -(num_steps-1)/divisor, num_steps))).apply(lambda x:int(x))

当我尝试这个时,我在 Python 3.7 中收到以下错误。

AttributeError: 'list' 对象没有属性 'apply'

有人可以帮忙吗?

【问题讨论】:

    标签: python list numpy python-3.7 attributeerror


    【解决方案1】:

    正如错误所说,list 类型没有apply 属性。 这就是说,如果您有一个列表 l 并且您想设置为 int,请输入您可以使用的每个元素:

    l = [int(x) for x in l]
    

    l = list(map(int,l))
    

    【讨论】:

      【解决方案2】:

      正如错误提示,list 没有 apply 方法。如果您想要做的是将每个元素转换为 int,您可以删除 lambda 函数并改用 astype(int)

      time_weight = list((100*np.exp(np.linspace(-1/divisor, -(num_steps-1)/divisor, num_steps))).astype(int))
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-05-25
        • 2022-01-20
        • 1970-01-01
        • 2015-07-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多