唐十 2022-07-03 14:26 采纳率: 57.1%
浏览 97
已结题

安装完Numpy之后运行报错,提示这个,怎么解决

安装完Numpy之后运行报错,提示这个,怎么解决

Traceback (most recent call last):
  File "E:\Python\lib\code.py", line 91, in runcode
    exec(code, self.locals)
  File "<input>", line 1, in <module>
  File "E:\PyCharm 2021.3.3\plugins\python\helpers\pydev\_pydev_bundle\pydev_umd.py", line 198, in runfile
    pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
  File "E:\PyCharm 2021.3.3\plugins\python\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "E:/Code/learning/com/shi/tang/learningNumPy/learningNumPy.py", line 12, in <module>
    array1 = np.arange([1, 2, 3, 4])
TypeError: unsupported operand type(s) for -: 'list' and 'int'
  • 写回答

2条回答 默认 最新

  • 请叫我问哥 Python领域新星创作者 2022-07-03 15:01
    关注

    array1 = np.arange([1, 2, 3, 4])
    这句写错了,要么应该是
    array1 = np.array([1, 2, 3, 4])
    要么应该是
    array1 = np.arange(1, 5)
    这两种写法都可以得到array([1, 2, 3, 4])

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 7月18日
  • 已采纳回答 7月10日
  • 创建了问题 7月3日