arrays - 如何检查多维数组是否为空
问题描述
我创建了这样的数组:
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')
解决方案
对于 python3,这是其中的一个动作:
if a.all()==None:
print("Empty list!")
else:
print('Not empty')
推荐阅读
- node.js - 调用 startSession() 时 Mongoose 断开连接
- python - Pandas:行值作为列
- apache-kafka - 卡夫卡经纪人如何找到彼此?
- c# - 是否有任何可能的方法来返回通过使用 .net Core MVC 中的 Entity Framework Core 的存储过程生成的结果..?
- spring-boot - 无法从外部访问运行在 Kubernetes-Pi-Cluster 上的 SpringBoot-Application
- redux - 错误:Reducer“计数器”在初始化期间返回未定义。如果传递给减速器的状态未定义
- unity3d - Unity:在不影响我的车的情况下撞到另一辆车
- angular9 - 如何更新相同的 ng-select 下拉列表
- mysql - 我想通过将格式转换为“DD-MM-YYYY”来将日期时间插入数据库
- angular - HTML selectors and directives not recognized