Indexing in numpy array

LuckyLucks
LuckyLucks used Ask the Experts™
on
hi

  I needed to convert the following stub operating on a python list , and make it suitable for a numpy array, but I can not seem to get the index function going for the numpy array


My method is called as follows: mymethod([1,2,3,4,5,6,7,8,9,10],3)   where b=3

  i=mylist.index(b)
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
NorieAnalyst Assistant

Commented:
For numpy arrays use square  brackets to index.
  i=mylist[b]

Open in new window

Author

Commented:
I need index OF a particular element 3 within the array. Not fetching the element at a particular index,
NorieAnalyst Assistant

Commented:
Sorry, I don't follow.

From what you posted what result would you expect?

Author

Commented:
I want the index of the element 3, which would be 2
Excel & VBA Expert
Most Valuable Expert 2018
Awarded 2015
Commented:
You may try something like this...

import numpy as np
mylist = np.array([1,2,3,4,5,6,7,8,9,10])
b = 3
i = np.where(mylist == b)
print(i)

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial