Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 通过预定义的步骤对列表进行排序_Python_List_Integral - Fatal编程技术网

Python 通过预定义的步骤对列表进行排序

Python 通过预定义的步骤对列表进行排序,python,list,integral,Python,List,Integral,如何在一个定义了步骤的列表中跳转,而不是在列表中的每个项目中,我希望能够跳转一些项目 t = np.linspace(0,100,1000) Fs = 6000 f = 200 func = 50*np.sin(2 * np.pi * f * t / Fs)+50 idx = [9 140 309 439 609 739 908] for i in (idx): it = integrate.simps(func[i], t[i]) print(it) &

如何在一个定义了步骤的列表中跳转,而不是在列表中的每个项目中,我希望能够跳转一些项目

t = np.linspace(0,100,1000)
Fs = 6000
f = 200

func = 50*np.sin(2 * np.pi * f * t / Fs)+50


idx = [9 140 309 439 609 739 908]
for i in (idx):
        it = integrate.simps(func[i], t[i])
        print(it)

>> gives me this :
5428.010261680331
5428.010261680331
5428.010261680331
5428.010261680331
5428.010261680331
5428.010261680331
5428.010261680331

''' wich is logical, because it itterates over every element,
but how to itterate like the following : 
i want to do integral of func from:
idx 1 to 2
idx 3 to 4 
idx 5 to 6
idx 7 to end wich dosent exist because the list is just 7 items
  so that it gives me only foor values'''

您想成对地遍历
idx
中的值吗

这篇文章有一些方法可以做到这一点。不确定如何处理最后一个元素没有下一个元素的边缘情况