megengine.core.tensor.array_method.ArrayMethodMixin.prod¶
- ArrayMethodMixin.prod(axis=None, keepdims=False)[源代码]¶
Returns the product of each row of the input tensor in the given dimension
axis
.If
axis
is a list of axises, reduce over all of them. Ifkeepdims
isTrue
, the shape of output tensor is the same as the input tensor, except in the dimension(s)axis
where it is of size 1. Otherwise,axis
is squeezed (seesqueeze
).- 参数
axis – the dimension or dimensions to reduce.
keepdims (
bool
) – 输出张量是否保留了轴 ndim 。
- 返回
输出张量。
实际案例
from megengine import tensor a = tensor([False, True, True, False]) b = tensor([1.0, 2.0, 3.0, 4.0]) print(a.prod().numpy()) print(b.prod().numpy())
输出:
0 24.0