mindspore.Tensor.all
- mindspore.Tensor.all(axis=None, keep_dims=False)
检查指定维度上是否所有元素均为 True。
- 参数:
axis (Union[int, tuple(int), list(int), Tensor], 可选) - 要减少的维度。如果为
None
,减少所有维度。默认None
。keep_dims (bool, 可选) - 输出tensor是否保留维度。默认
False
。
- 返回:
Tensor
- 支持平台:
Ascend
GPU
CPU
样例:
>>> import mindspore >>> x = mindspore.tensor([[True, False], [True, True]]) >>> >>> # case 1: By default, mindspore.Tensor.all tests along all the axes. >>> x.all() Tensor(shape=[], dtype=Bool, value= False) >>> >>> # case 2: Reduces a dimension along axis 1, with keep_dims False. >>> x.all(axis=1) Tensor(shape=[2], dtype=Bool, value= [False, True]) >>> >>> # case 3: Reduces a dimension along axis (0, 1), with keep_dims False. >>> x.all(axis=(0,1)) Tensor(shape=[], dtype=Bool, value= False) >>> >>> # case 4: Reduces a dimension along axis [0, 1], with keep_dims True. >>> x.all(axis=[0,1], keep_dims=True) Tensor(shape=[1, 1], dtype=Bool, value= [[False]])
- mindspore.Tensor.all(dim=None, keepdim=False)
检查指定维度上是否所有元素均为 True。
- 参数:
dim (Union[int, tuple(int), list(int), Tensor], 可选) - 要减少的维度。如果为
None
,减少所有维度。默认None
。keepdim (bool, 可选) - 输出tensor是否保留维度。默认
False
。
- 返回:
Tensor
- 支持平台:
Ascend
GPU
CPU
样例:
>>> import mindspore >>> x = mindspore.tensor([[True, False], [True, True]]) >>> >>> # case 1: By default, mindspore.Tensor.all tests along all the axes. >>> x.all() Tensor(shape=[], dtype=Bool, value= False) >>> >>> # case 2: Reduces a dimension along dim 1, with keepdim False. >>> x.all(dim=1) Tensor(shape=[2], dtype=Bool, value= [False, True]) >>> >>> # case 3: Reduces a dimension along dim (0, 1), with keepdim False. >>> x.all(dim=(0,1)) Tensor(shape=[], dtype=Bool, value= False) >>> >>> # case 4: Reduces a dimension along dim [0, 1], with keepdim True. >>> x.all(dim=[0,1], keepdim=True) Tensor(shape=[1, 1], dtype=Bool, value= [[False]])