def numel(x):
if hasattr(x, 'shape'):
return reduce(lambda x, y: x * y, x.shape)
if hasattr(x, 'size'):
return reduce(lambda x, y: x * y, x.size)
if isinstance(x, Iterable):
return reduce(lambda x, y: x * y, x)
return x.n
评论列表
文章目录