views:

56

answers:

2

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

+2  A: 

You should probably clarify whether you mean a list, a numpy array, an array.array, or something else...

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

Joe Kington
+2  A: 
lst = range(10)

for n, N in enumerate(lst):
    print lst[n:]
killown