# Attributeerror: numpy.ndarray object has no attribute index ( Solved )

Numpy is a python package that allows you to create a numpy array that makes you to performs complex mathematical calculations. Suppose you want to find the index of the array elements and encounter the Error Attributeerror: numpy.ndarray object has no attribute index. In this post, you will learn how to solve this error.

## What causes attributeerror: numpy.ndarray object has no attribute index?

The main reason for getting this numpy.ndarray object has no attribute index error is that you are trying to find the index of the values by applying index on the entire numpy array. This index attribute does not exist in the numpy packages.

You will get the error when you will run the below lines of code.

``````import numpy as np
numpy_array = np.array([10,20,30,40,50])
numpy_array.index(40)``````

Output

## Solve numpy.ndarray object has no attribute index Error

There are two ways to solve this AttributeError. If you want to find the specific index of the element then use the np.where() function. And if you want to find the index of all the nonzero elements then use the np.argwhere().

Let’s execute the code for each solution.

### Find the index of the element

Pass the elements inside the np.where() to find its index. For example, if I want to find the index of the 40th element then I will use the below lines of code.

``````import numpy as np
numpy_array = np.array([10,20,30,40,50])
np.where(numpy_array==40)``````

Output

### Find the indices of all the non-zero elements

You will pass the numpy array as an argument of np.argwhere() to find the indices of the non-zero elements.

Run the below lines of code to execute it.

``````import numpy as np
numpy_array = np.array([10,20,30,40,50])
np.argwhere(numpy_array)``````

Output

## Conclusion

If you want to find the index of the elements in a numpy array then you don’t have to use the index on the entire numpy array like your_numpy.index. Instead, use the numpy.where() and your_numpy_array.argwhere() to find the index of single elements and non-zero elements of the array respectively. The above method will solve the attributerError.

I hope you have liked this tutorial. If you have any queries then you can contact us for more help.