npires
npires

Reputation: 6693

Numpy return array of index

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.

Upvotes: 1

Views: 146

Answers (1)

Saullo G. P. Castro
Saullo G. P. Castro

Reputation: 58885

You can do:

a = np.array([-3. , -1.8, -0.6,  0.6,  1.8])
indices = np.arange(a.shape[0])

Upvotes: 1

Related Questions