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..

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

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值