close

How to get the indices list of all NaN value in numpy array?

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How to get the indices list of all NaN value in numpy array in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

How to get the indices list of all NaN value in numpy array?

  1. How to get the indices list of all NaN value in numpy array?

    You can use np.where to match the boolean conditions corresponding to Nan values of the array and map each outcome to generate a list of tuples.

  2. get the indices list of all NaN value in numpy array

    You can use np.where to match the boolean conditions corresponding to Nan values of the array and map each outcome to generate a list of tuples.

Method 1

np.isnan combined with np.argwhere

x = np.array([[1,2,3,4],
              [2,3,np.nan,5],
              [np.nan,5,2,3]])
np.argwhere(np.isnan(x))

output:

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

Method 2

You can use np.where to match the boolean conditions corresponding to Nan values of the array and map each outcome to generate a list of tuples.

>>>list(map(tuple, np.where(np.isnan(x))))
[(1, 2), (2, 0)]

Summery

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read