What is equivalent of Matlab nan( ) in python?

Question:

this is my MATLAB code with the following output:

pad=nan(1,5)

pad =

   NaN   NaN   NaN   NaN   NaN

I want to do the same operation in python, I tried np.isnan(1,6) but this is not working. what should I used to get the same results. thank you

Asked By: user20191650

||

Answers:

You can use np.full() to create a multi-dimensional array pre-populated with the same values:

np.full((1, 5), np.nan)

which produces:

array([[nan, nan, nan, nan, nan]])
Answered By: sj95126

You can use numpy.zeros(N) + numpy.nan, where N is the number of NaN you want in your array.

import numpy as np

N = 6
nan_array = np.zeros(N) + np.nan

Will produce the following array –

[array([nan, nan, nan, nan, nan, nan])]

Answered By: Faruk Ahmad
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.