为什么在python中使用.count()时会出现AttributeError

Pyt*_*lex -1 python arrays count attributeerror

array1=[ 0 5 6 6 6 0 6 0 6 8 0 19 24 7 0 4 9 14 12 0 22 17 1 0 19 6 17 4 7 0 17 24 0 6 9 22]

i=0
while i<23
      m= array1.count(i)
      i=i+1
Run Code Online (Sandbox Code Playgroud)

AttributeError: 'numpy.ndarray' object has no attribute 'count'

为什么在使用.count()时会出现属性错误?我需要导入一些东西吗?

Bjö*_*lex 7

那么,根据文档,ndarray根本没有count方法.

您发布的代码与您提供给我们的错误消息相矛盾.在您的代码中,您创建了一个简单的Python列表,但您的错误消息表明您实际上正在使用numpy ndarray.