[英]Dividing Consecutive float numbers in a list
Hey just coming back to python for the some homework, and i'm able to figure out how to divide consecutive numbers in a list. 嘿,刚回到python做一些功课,我就能弄清楚如何在列表中分割连续的数字。 I've tried using slices, and adding another range to subscript the numbers like below.
我尝试使用切片,并添加另一个范围以对数字进行下标,如下所示。
x, y = vec_time()
for ii in y:
for jj in range(1-101):
print(ii[jj+1]/ii[jj])
My Y list looks like this buy 20 times longer. 我的Y清单看起来像这样,购买时间延长了20倍。
[0.014009237289428711, 0.017012834548950195, 0.020015716552734375, 0.019011974334716797, 0.01801300048828125,
You can use numpy
and do the following 您可以使用
numpy
并执行以下操作
import numpy as np
arr = np.array(your_list)
result = arr[:-1]/arr[1:]
This gives the following for 这给出了以下内容
your_list = [1,2,3,4,5]
result = [1.0/2.0,2.0/3.0, 3.0/4.0,4.0/5.0]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.