欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

AttributeError: 'list' object has no attribute 'ndim'

程序员文章站 2022-03-26 23:20:05
...

ERROR:

AttributeError                            Traceback (most recent call last)
<ipython-input-6-9b77ac20aa23> in <module>()
      1 # Print the `images` dimensions
----> 2 print(images.ndim)
      3 
      4 # Print the number of `images`'s elements
      5 print(images.size)

AttributeError: 'list' object has no attribute 'ndim'

Solution:

It tried to get shape of input by reading ndim attribute of numpy array and failed.

Just simply transform it using np.array:

import numpy as np
...
images=np.array(images)
labels=np.array(labels)