小编Ma *_*Tze的帖子

从带有map的类方法调用NumPy时出现Python错误

以下代码抛出了错误:

Traceback (most recent call last):
  File "", line 25, in <module>
    sol = anna.main()
  File "", line 17, in main
    sol = list(map(self.eat, self.mice))
  File "", line 12, in eat
    calc = np.sqrt((food ** 5))
AttributeError: 'int' object has no attribute 'sqrt'
Run Code Online (Sandbox Code Playgroud)

码:

import numpy as np
#import time

class anaconda():

    def __init__(self):
        self.mice = range(10000)

    def eat(self, food):
        calc = np.sqrt((food ** 5))
        return calc

    def main(self):

        sol = list(map(self.eat, self.mice))
        return sol


if __name__ == '__main__':
    #start …
Run Code Online (Sandbox Code Playgroud)

python numpy

16
推荐指数
1
解决办法
1802
查看次数

标签 统计

numpy ×1

python ×1