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
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]])
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])]
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
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]])
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])]