累积连乘
累积连乘(cumprod )
矩阵的运算
matlab中的算法描述如下:
B = cumprod(A) returns the cumulative product along different dimensions of an array.
If A is a vector, cumprod(A) returns a vector containing the cumulative product of the elements of A.
If A is a matrix, cumprod(A) returns a matrix the same size as A containing the cumulative products for each column of A.
If A is a multidimensional array, cumprod(A) works on the first nonsingleton dimension.
B = cumprod(A,dim) returns the cumulative product of the elements along the dimension of A specified by scalar dim. For example,
cumprod(A,1) increments the first (row) index, thus working along the rows of A.
中文翻译如下:
B = cumprod(A)返回数组不同程度的累积连乘的结果。
如果A是一个向量,将返回一个包含A各元素累积连乘的结果的向量,元素个数与原向量相同。
如果A是一个矩阵,将返回一个和A同样大小的,包含A每一列向量累积连乘的结果的矩阵。
如果A是一个多为向量,cumprod(A)只对第一个nonsingleton(sorry,不认识也查不到)的维度上有效。
matlab中给出的例子如下:
输入:cumprod(1:5)
返回:ans =
1 2 6 24 120
输入:A = [1 2 3; 4 5 6];
cumprod(A)
返回:ans =
1 2 3
4 10 18
再输入:cumprod(A,2)
返回:ans =
1 2 6
4 20 120