首页 > 解决方案 > 如何检查多维数组是否为空

问题描述

我创建了这样的数组:

a = np.empty((2,3), dtype=object)

如何检查它是否为空?我使用以下方法没有任何成功。

a = np.empty((2,3), dtype=object)
#1:
if a == []: 
   print("Empty list!")
else:
   print('Not empty')

#2:
if not a:
   print("List is empty")
else:
   print('Not empty')

#3:
if a:
   print('Not empty')

标签: arrayspython-3.xlist

解决方案


对于 python3,这是其中的一个动作:

if a.all()==None: 
   print("Empty list!")
else:
   print('Not empty')

推荐阅读