pytorch 判断张量为空
if min(a.shape) == 0: # 张量a为空
pass
else: # 张量a不为空
pass
变量为空可能有以下错误:
- RuntimeError: operation does not have an identity.
- RuntimeError: cannot perform reduction function max on tensor with no elements because the operation does not have an identity
- RuntimeError: cannot perform reduction function min on tensor with no elements because the operation does not have an identity