如何跳过列表中的值?

-2 投票
1 回答
825 浏览
提问于 2025-05-01 02:01

我需要在一个列表中跳过一些值(从100到100),所以我写了以下代码:

我想把I中的值从100乘起来:

lenI = len(I)
bkgnoise=[]
i=0
while i < lenI:
    rvalue = random.random()
    bkgnoise.append(I[i]*rvalue)
    i+=100

但是我总是遇到一个错误,提示'异常.ValueError: x和y必须有相同的第一维度'

暂无标签

1 个回答

2

如果你想在一个列表中跳过一些值,可以试着用一个循环,每次增加100来遍历这个列表。

for i in xrange(0,20000,100):
     print i

撰写回答