Movatterモバイル変換


[0]ホーム

URL:


SciPy

numpy.cumsum

numpy.cumsum(a,axis=None,dtype=None,out=None)[source]

Return the cumulative sum of the elements along a given axis.

Parameters:

a : array_like

Input array.

axis : int, optional

Axis along which the cumulative sum is computed. The default(None) is to compute the cumsum over the flattened array.

dtype : dtype, optional

Type of the returned array and of the accumulator in which theelements are summed. Ifdtype is not specified, it defaultsto the dtype ofa, unlessa has an integer dtype with aprecision less than that of the default platform integer. Inthat case, the default platform integer is used.

out : ndarray, optional

Alternative output array in which to place the result. It musthave the same shape and buffer length as the expected outputbut the type will be cast if necessary. Seedoc.ufuncs(Section “Output arguments”) for more details.

Returns:

cumsum_along_axis : ndarray.

A new array holding the result is returned unlessout isspecified, in which case a reference toout is returned. Theresult has the same size asa, and the same shape asa ifaxis is not None ora is a 1-d array.

See also

sum
Sum array elements.
trapz
Integration of array values using the composite trapezoidal rule.
diff
Calculate the n-th discrete difference along given axis.

Notes

Arithmetic is modular when using integer types, and no error israised on overflow.

Examples

>>>a=np.array([[1,2,3],[4,5,6]])>>>aarray([[1, 2, 3],       [4, 5, 6]])>>>np.cumsum(a)array([ 1,  3,  6, 10, 15, 21])>>>np.cumsum(a,dtype=float)# specifies type of output value(s)array([  1.,   3.,   6.,  10.,  15.,  21.])
>>>np.cumsum(a,axis=0)# sum over rows for each of the 3 columnsarray([[1, 2, 3],       [5, 7, 9]])>>>np.cumsum(a,axis=1)# sum over columns for each of the 2 rowsarray([[ 1,  3,  6],       [ 4,  9, 15]])

Previous topic

numpy.cumprod

Next topic

numpy.nancumprod

  • © Copyright 2008-2009, The Scipy community.
  • Last updated on Jun 10, 2017.
  • Created usingSphinx 1.5.3.

[8]ページ先頭

©2009-2025 Movatter.jp