【问题标题】:itterate over a list by pre-defined steps通过预定义的步骤迭代列表
【发布时间】:2019-04-03 12:48:47
【问题描述】:

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

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

【问题讨论】:

    标签: python list integral


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-08-03
      • 1970-01-01
      • 2015-03-09
      • 2017-01-05
      • 1970-01-01
      • 2022-01-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多