cumprod
累积产品
Description
返回the cumulative product ofb
= cumprod(一个
)一个
starting at the beginning of the first array dimension in一个
whose size does not equal 1.
如果
一个
是一个向量,然后acprod(a)
返回包含元素元素元素的矢量一个
。如果
一个
是a matrix, thenacprod(a)
返回包含每一列累积产品的矩阵s manbetx 845一个
。如果
一个
是a multidimensional array, thenacprod(a)
沿着first nonsingleton dimension。
Examples
Cumulative Product of Vector
从1
to5
。这elementb(2)
是the product ofA(1)
和A2)
,,,,whileb(5)
是the product of elementsA(1)
throughA(5)
。
a = 1:5;b = cumprod(a)
b=1×512 6 24 120
Cumulative Product of Each Column in Matrix
Define a 3-by-3 matrix whose elements correspond to their linear indices.
a =[1 4 7; 2 5 8; 3 6 9]
a =3×314 7 2 5 8 3 6 9
Find the cumulative product of the columns of一个
。这elementb(5)
是the product ofA(4)
和A(5)
,,,,whileB(9)
是the product ofA(7)
,,,,A(8)
, 和A(9)
。
b = cumprod(a)
b=3×314 7 2 20 56 6 120 504
Cumulative Product of Each Row in Matrix
定义一个2 x-3矩阵,其元素对应于线性索引。
a = [1 3 5;2 4 6]
a =2×31 3 5 2 4 6
找到行的累积产物一个
。这elementb(3)
是the product ofA(1)
和A(3)
,,,,whileb(5)
是the product ofA(1)
,,,,A(3)
, 和A(5)
。
b = cumprod(一个,,,,2)
b=2×31 3 15 2 8 48
带双输出的逻辑输入
创建一系列逻辑值。
a =[true false true; true true false]
a =2x3逻辑数组10 1 1 1 0
找到行的累积产物一个
。
b = cumprod(一个,,,,2)
b=2×31 0 0 1 1 0
这output has typedouble
。
(b)类
ans ='double'
Reverse Cumulative Product
在1到10之间创建一个随机整数的3 x-3矩阵。
RNGdefault; A = randi([1,10],3)
a =3×39 10 3 10 7 6 2 1 10
沿列计算累积产品。指定'撤销'
在每一列中从底部到顶部工作的选项。结果的大小与一个
。
b = cumprod(一个,,,,'撤销')
b=3×3180 70 180 20 7 60 2 1 10
Vector with南
值
创建一个载体南
值并计算累积产品。s manbetx 845默认,cumprod
包括南
值。当您包括时南
计算中的值,累积产物变为南
as soon as the first南
价值一个
是encountered.
a = [1 3 nan 2 4 nan];b = cumprod(a)
b=1×613 NaN NaN NaN NaN
Ignore南
使用累积产品计算中的值'omitnan'
option.
b = cumprod(一个,,,,'omitnan')
b=1×613 3 6 24 24
输入参数
一个
-Input array
vector|矩阵|multidimensional array
输入阵列,指定为向量,矩阵或多维数组。
Data Types:double
|single
|int8
|int16
|int32
|int64
|uint8
|uint16
|uint32
|uint64
|逻辑
复杂的数字支持:万博1manbetxYes
暗淡
-沿着操作的维度
positive integer scalar
沿着操作的维度,指定为正整数标量。如果未指定尺寸,则默认值是大于1的大小的第一个数组维度。
Consider a two-dimensional input array,一个
。
acprod(a,1)
在列的连续元素上工作一个
并返回每一列的累积产品。s manbetx 845acprod(a,2)
在行的连续元素上工作一个
和返回the cumulative products of each row.
cumprod
返回一个
如果暗淡
大于ndims(A)
。
方向
-Direction of cumulation
'向前'
(default) |'撤销'
累积方向,指定为'向前'
(默认)或'撤销'
。
'向前'
来自1
to结尾
of the active dimension.'撤销'
来自结尾
to1
of the active dimension.
Nanflag
-南
(健康)状况
'includeenan'
(default) |'omitnan'
南
条件,指定为以下值之一:
'includeenan'
-Include南
values from the input when computing each product, resulting in南
values in the output.'omitnan'
- 忽视南
values in the input. The product of elements containing南
values is the product of all non-南
元素。如果所有元素是南
, 然后cumprod
返回1。
Output Arguments
b
- 累积产品阵列
vector | matrix | multidimensional array
累积产品array, returned as a vector, matrix, or multidimensional array of the same size as the input array一个
。
班级b
与班级相同一个
除非一个
是逻辑
, 在这种情况下b
是double
。
更多关于
第一个nonsingleton维度
第一个非语言尺寸是数组的第一个维度,其大小不等于1
。
For example:
如果
X
是一个1 x-n行矢量,那么第二维是第一个nonsingleton尺寸X
。如果
X
是一个1 x-0-b的空数组,那么第二维是第一个nonsingleton维X
。如果
X
1-by-1-by-3数组,那么third dimension is the first nonsingleton dimension ofX
。
Tips
MATLAB中的许多累积功能®万博1manbetx支持
'撤销'
option. This option allows quick directional calculations without needing a flip or reflection of the input array.
Extended Capabilities
高阵列
用比在内存中拟合更多的行的数组计算。
C/C++ Code Generation
使用MATLAB®CODER™生成C和C ++代码。
Usage notes and limitations:
不支持逻辑输入。万博1manbetx投入到
double
first.Code generation does not support sparse matrix inputs for this function.
GPU Code Generation
Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.
Usage notes and limitations:
不支持逻辑输入。万博1manbetx投入到
double
first.Code generation does not support sparse matrix inputs for this function.
Thread-Based Environment
使用MATLAB®在后台运行代码backgroundPool
or accelerate code with Parallel Computing Toolbox™螺纹池
。
此功能完全支持基于线程的环境。万博1manbetx有关更多信息,请参阅在基于线程的环境中运行MATLAB功能。
GPU Arrays
使用并行计算工具箱™在图形处理单元(GPU)上运行加速代码。
Usage notes and limitations:
这
Nanflag
不支持争论。万博1manbetx这order of the products within the
comprod
operation is not defined. Therefore, thecumprod
operation on agpuArray
might not return exactly the same answer as thecumprod
operation on the corresponding MATLAB numeric array. The differences might be significant when一个
是a signed integer type.
有关更多信息,请参阅在GPU上运行MATLAB功能(Parallel Computing Toolbox)。
分布式阵列
Partition large arrays across the combined memory of your cluster using Parallel Computing Toolbox™.
Usage notes and limitations:
这order of the products within the
comprod
operation is not defined. Therefore, thecumprod
在分布式数组上的操作可能不会与cumprod
operation on the corresponding MATLAB numeric array. The differences might be significant when一个
是a signed integer type.
有关更多信息,请参阅运行具有分布式数组的MATLAB功能(Parallel Computing Toolbox)。
版本历史记录
Open Example
You have a modified version of this example. Do you want to open this example with your edits?
MATLAB Command
您单击了与此MATLAB命令相对应的链接:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
选择一个网站
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select:。
您还可以从以下列表中选择一个网站:
How to Get Best Site Performance
选择中国网站(中文或英语)以获得最佳场地性能。其他Mathworks乡村网站未针对您所在的访问进行优化。
美洲
- 一个mérica Latina(西班牙语)
- 加拿大(English)
- 美国(English)
欧洲
- Netherlands(English)
- Norway(English)
- Österreich(德意志)
- 葡萄牙(English)
- Sweden(English)
- 瑞士
- United Kingdom(English)
一个sia Pacific
- 一个ustralia(English)
- 印度(English)
- New Zealand(English)
- 中国
- 日本(日本語)
- 한국(한국어)