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

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

 

 

 

 

全部评论

相关推荐

05-14 20:34
门头沟学院 Java
窝补药贝八股:管他们,乱说,反正又不去,直接说680
点赞 评论 收藏
分享
07-03 11:02
中山大学 C++
字节刚oc,但距离九月秋招很近了有两段互联网实习,非腾讯字节。不敢赌转正,现在在纠结去还是不去如果实习俩月离职会有什么后果吗
阿城我会做到的:不去后悔一辈子,能否转正取决于ld的态度,只要他不卡,答辩就是走流程,个人觉得可以冲一把
投递字节跳动等公司9个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务