all
对指定维度上的 Tensor 元素进行逻辑与运算,并输出相应的计算结果。
备注
别名支持: 参数名 input 可替代 x, dim 可替代 axis。
参数
x (Tensor)- 输入变量为多维 Tensor,数据类型为 bool、float32、float64、int32、int64。 别名:
inputaxis (int | list | tuple,可选)- 计算逻辑与运算的维度。如果为 None,则计算所有元素的逻辑与并返回包含单个元素的 Tensor 变量,否则必须在 \([−rank(x),rank(x)]\) 范围内。如果 \(axis [i] <0\),则维度将变为 \(rank+axis[i]\),默认值为 None。 别名:
dimkeepdim (bool,可选) - 是否在输出 Tensor 中保留减小的维度。除非 keepdim 为 True,否则输出 Tensor 的维度将比输入 Tensor 小一维,默认值为 False。
name (str,可选) - 具体用法请参见 api_guide_Name,一般无需设置,默认值为 None。
out (Tensor,可选) - 指定输出结果的 Tensor,默认值为 None。
返回
Tensor,在指定维度上进行逻辑与运算的 Tensor,数据类型和输入数据类型一致。
代码示例
>>> import paddle >>> # x is a bool Tensor with following elements: >>> # [[True, False] >>> # [True, True]] >>> x = paddle.to_tensor([[1, 0], [1, 1]], dtype='int32') >>> x Tensor(shape=[2, 2], dtype=int32, place=Place(cpu), stop_gradient=True, [[1, 0], [1, 1]]) >>> x = paddle.cast(x, 'bool') >>> # out1 should be False >>> out1 = paddle.all(x) >>> out1 Tensor(shape=[], dtype=bool, place=Place(cpu), stop_gradient=True, False) >>> # out2 should be [True, False] >>> out2 = paddle.all(x, axis=0) >>> out2 Tensor(shape=[2], dtype=bool, place=Place(cpu), stop_gradient=True, [True , False]) >>> # keepdim=False, out3 should be [False, True], out.shape should be (2,) >>> out3 = paddle.all(x, axis=-1) >>> out3 Tensor(shape=[2], dtype=bool, place=Place(cpu), stop_gradient=True, [False, True ]) >>> # keepdim=True, out4 should be [[False], [True]], out.shape should be (2, 1) >>> out4 = paddle.all(x, axis=1, keepdim=True) >>> out4 Tensor(shape=[2, 1], dtype=bool, place=Place(cpu), stop_gradient=True, [[False], [True ]])