[英]Accessing later index in array using enumerate(array) Python
hey guys, how would you access an array from array[n] in an array of 100 floats in this for loop (i need the enumerate): 嗨,大家好,在这个for循环中,如何从array [n]中的100个浮点数数组中访问数组(我需要枚举):
for index,value in enumerate(array):
#do stuff with array[n]
n=n+1
im trying to make it so that it operates in a smaller and smaller space each iteration.. 我正在尝试使其每次迭代都在越来越小的空间内运行。
thanks 谢谢
You should probably clarify whether you mean a list, a numpy array, an array.array , or something else... 您可能应该弄清楚您的意思是列表, numpy数组, array.array还是其他...
That having been said, it sounds like you want to slice whatever your "array" is. 话虽这么说,听起来好像您想分割任何“数组”。 Perhaps something like this?: 也许是这样的:
data = range(10)
for i in range(len(data)):
print data[i:]
Which would output: 哪个会输出:
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
[1, 2, 3, 4, 5, 6, 7, 8, 9]
[2, 3, 4, 5, 6, 7, 8, 9]
[3, 4, 5, 6, 7, 8, 9]
[4, 5, 6, 7, 8, 9]
[5, 6, 7, 8, 9]
[6, 7, 8, 9]
[7, 8, 9]
[8, 9]
[9]
Hope that helps a bit, anyway... 希望无论如何会有所帮助...
lst = range(10)
for n, N in enumerate(lst):
print lst[n:]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.