#多在编译器里尝试新操作
import numpy as np
for i range(100):
  eval1 = {"A": ''"}
  eval2 = {"A": [[1], [2]]}
      if i%2 == 0:
      ar = np.array(eval1['A'])  #此时打印ar,里面什么都没有
      else:
      ar = np.array(eval2["A"])     #此时打印ar,是一个二维数组
    
  if ar.shape == ():  #不能用len来判断,array没有len用法;对于数组中有元素的,不能够使用if
    print("数组中什么都没有")

# if all(ar):#TypeError: iteration over a 0-d array
if ar.all(): # TypeError: cannot perform reduce with flexible type
print("ar为空")


# if not all(ar2):
if not ar2.all():
print("ar2为空")


 

相关文章:

  • 2021-12-04
  • 2021-12-04
  • 2022-12-23
  • 2022-02-08
  • 2021-12-01
  • 2021-12-04
  • 2022-01-16
  • 2021-12-13
猜你喜欢
  • 2021-10-03
  • 2021-07-24
  • 2022-12-23
  • 2021-12-04
  • 2022-12-23
  • 2021-12-04
  • 2022-12-23
相关资源
相似解决方案