Search code examples
pythonarraysfor-loopscientific-computing

Trim for loop between datapoints from a 2d array


I loaded a file.dat as a 2d array

data = np.loadtxt('file.dat')

I have used a for loop as to iterative over all points in this array

for i in range(len(data):

If I wanted to only do a for loop between points 100-200, how would i do this? I currently have:

for i in range(data[100], data[200]):

but I get an error

"TypeError: only integer scalar arrays can be converted to a scalar index"


Solution

  • You would just specify the range without indexing the data like so:

    for i in range(100, 201):