0

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"

1 Answer 1

0

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

for i in range(100, 201):
1
  • Ahh I see, its that simple. I'm not use to python syntax, thanks!
    – Kryoomi
    Commented Mar 4, 2021 at 17:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.