python 函数解析 (numpy 篇)

每碰到一个不懂的就查查源码,看看参数怎么写的。注意多积累。

.cumsum

cumsum源文档

numpy.cumsum(aaxis=Nonedtype=Noneout=None)

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 the elements are summed. If dtype is not specified, it defaults to the dtype of a, unless a has an integer dtype with a precision less than that of the default platform integer. In that case, the default platform integer is used.

out : ndarray, optional

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

Returns:

cumsum_along_axis : ndarray.

A new array holding the result is returned unless out is specified, in which case a reference to out is returned. The result has the same size as a, and the same shape as a if axis is not None or a is a 1-d array.

例如:

a = np.array([[1,2,3], [4,5,6]])
# array([[1, 2, 3],[4, 5, 6]])
np.cumsum(a)
# array([ 1,  3,  6, 10, 15, 21])

 1

1+2

1+2+3..

不同于斐波那契数列的相加规则。

 

 

 

 

全部评论

相关推荐

10-13 17:47
门头沟学院 Java
wulala.god:图一那个善我面过,老板网上找的题库面的
点赞 评论 收藏
分享
小谷围鸡肉卷阿姨:+1,腾子投完一动不动
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务