1

Probably this is a dummy question! But I simply can't find the answer!

For the following array np.arange(-3,3,1.2) I get this:

array([-3. , -1.8, -0.6,  0.6,  1.8])

and for this I want to get an index array like the following:

array([0, 1, 2, 3, 4])

Thanks in advance.

3
  • 6
    Surely you're not just looking for np.arange(5). So can you clarify the problem? Commented Apr 11, 2014 at 18:25
  • What do you want to do with the index? Commented Apr 11, 2014 at 18:27
  • If you want to get the indices to that particular array (so that the lengths match), you could use np.arange(len(np.arange(-3, 3, 1.2))) Commented Apr 11, 2014 at 20:28

1 Answer 1

1

You can do:

a = np.array([-3. , -1.8, -0.6,  0.6,  1.8])
indices = np.arange(a.shape[0])
Sign up to request clarification or add additional context in comments.

1 Comment

@npires Don't hesitate to upvote the answer if you liked it (you can do it since you have >= 15 reputation)

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.