简体   繁体   English

将numpy数组中的元素顺序添加到新数组中

[英]Sequentially add elements in numpy array into new array

I'm curious if there is a built in function to transform an array of values into a cumulative array of values. 我很好奇是否有内置函数将值数组转换为值的累积数组。

Example: 例:

input = np.asarray([0.000,1.500,2.100,5.000])

into

[0.000,1.500,3.600,8.600] [0.000,1.500,3.600,8.600]

Thanks! 谢谢!

Use in-built cumsum from NumPy to get the cumulative sum of your array inputt as 使用内置cumsum从NumPy的让你的阵列的累积和inputt

inputt = np.asarray([0.000,1.500,2.100,5.000])
print (np.cumsum(inputt)) 

# [0.  1.5 3.6 8.6]

I renamed your array because input is already an in-built function in python to get the user input from the keyboard 我重命名了数组,因为input已经是python中的内置函数,可从键盘获取用户输入

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM