Is there anyway to create a numpy array that returns np.nan when indexed out of bounds? Eg
x = np.array([1,2,3])
x[1] # 2
x[-2] # np.nan
x[5] # np.nan
The closest thing I found was np.pad.
I know I could write a wrapper class, but I was wondering if there's any efficient numpy way to do it.