I have a 2d array with shape (x, y) which I want to convert to a 3d array with shape (x, y, 1). Is there a nice Pythonic way to do this?
If you just want to add a 3rd axis (x,y) to (x,y,1), Numpy allows you to easily do this using the dstack command.
dstack
import numpy as np a = np.eye(3) # your matrix here b = np.dstack(a).T
You need to transpose (.T) it to get it into the (x,y,1) format you want.
.T