How do I obtain the index list in a NumPy Array of all the NaN values present using Python

0 votes

Hi all, pretty simple question but I am held back.

Let us consider the case where I have created a NumPy array which is valid. 

Consider the example:


And now, let us say that I want to be presented with a certain list that consists of all of the index values of the missing elements. In this case, the missing elements is [(1,2),(2,0)] as you can see.

How can I go about doing this? 

Appreciate all the help!

Jan 30, 2019 in Python by Anirudh
• 2,080 points

1 answer to this question.

0 votes

Hi, it is pretty simple, to be honest. Check this out:

You will have to make use of np.isnan along with no.argwhere to achieve what you desire in this question.

The following code will help give you some clarity:

x = np.array([[1,2,3,4],

The output for the above code is as follows:

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

I am sure this helped to answer your query, cheers!

answered Jan 30, 2019 by Nymeria
• 3,540 points

Related Questions In Python

0 votes
1 answer

how do I check the length of an array in a python program?

lets say we have a list mylist = ...READ MORE

answered Mar 12, 2019 in Python by Mohammad
• 3,230 points
0 votes
2 answers

How can I get the count of a list in Python?

n=[1,2,3,4,5,6,7,8,9] print(len(n)) =9 READ MORE

answered Dec 10, 2020 in Python by anonymous
+1 vote
1 answer
0 votes
1 answer

how do i print only the last two letters in a string using regular expression in python?

$ to match the end of the ...READ MORE

answered Mar 15, 2019 in Python by Waseem
• 4,540 points
0 votes
1 answer
0 votes
1 answer

Doubt in numpy.vstack

The vstack function in numpy will stack ...READ MORE

answered Jul 30, 2019 in Python by Esha
0 votes
1 answer
0 votes
1 answer

How to save numpy array?

Hi@akhtar, You can use function to save ...READ MORE

answered Jun 22, 2020 in Python by MD
• 95,320 points
0 votes
1 answer

In NumPy how do I get the maximum of subsets? Python

You can use np.maximum.reduceat: >>> _, idx = np.unique(g, ...READ MORE

answered Nov 9, 2018 in Python by Nymeria
• 3,540 points