I'm trying to pad an array with np.nan
import numpy as np
print np.version.version
# 1.10.2
combine = lambda real, theo: np.vstack((theo, np.pad(real, (0, theo.shape[0] - real.shape[0]), 'constant', constant_values=np.nan)))
real = np.arange(20)
theoretical = np.linspace(0, 20, 100)
result = combine(real, theoretical)
np.any(np.isnan(result))
# False
Inspecting result, it seems instead of np.nan, the array is getting padded with -9.22337204e+18. What's going on here? How can I get np.nan?
real = np.arange(20, dtype=float).np.pad(real, (0, theo.shape[0] - real.shape[0]), 'constant', constant_values=np.nan)whenrealis an integer array.realwas an integer array. Why does this behaviour happen with integers?np.nanis a float.