maxframe.tensor.cumprod#

maxframe.tensor.cumprod(a, axis=None, dtype=None, out=None)[源代码]#

返回沿给定轴的元素的累积乘积。

参数:
  • a (array_like) -- 输入张量。

  • axis (int, optional) -- 计算累积乘积的轴。默认情况下输入会被展平。

  • dtype (dtype, optional) -- 返回张量的类型,以及元素相乘时所用累加器的类型。如果未指定 dtype,则默认为 a 的 dtype,除非 a 具有精度低于默认平台整数的整数类型。在这种情况下,将使用默认平台整数。

  • out (Tensor, optional) -- 用于存放结果的替代输出张量。它必须具有与预期输出相同的形状和缓冲区长度,但结果值的类型在必要时将被转换。

返回:

cumprod -- 返回一个包含结果的新张量,除非指定了 out,此时返回对 out 的引用。

返回类型:

Tensor

参见

numpy.doc.ufuncs

“输出参数”部分

备注

使用整数类型时运算是模运算,溢出时不会引发错误。

示例

>>> import maxframe.tensor as mt
>>> a = mt.array([1,2,3])
>>> mt.cumprod(a).execute() # intermediate results 1, 1*2
...                         # total product 1*2*3 = 6
array([1, 2, 6])
>>> a = mt.array([[1, 2, 3], [4, 5, 6]])
>>> mt.cumprod(a, dtype=float).execute() # specify type of output
array([   1.,    2.,    6.,   24.,  120.,  720.])

a 每一列(即跨行)的累积乘积:

>>> mt.cumprod(a, axis=0).execute()
array([[ 1,  2,  3],
       [ 4, 10, 18]])

a 每一行(即跨列)的累积乘积:

>>> mt.cumprod(a,axis=1).execute()
array([[  1,   2,   6],
       [  4,  20, 120]])