numpy: extending arrays along a new axis?

Here is one way:

import scipy
X = scipy.rand(9,4,1)
Y = X.repeat(4096,2)

If X is given to you as only (9,4), then

import scipy
X = scipy.rand(9,4)
Y = X.reshape(9,4,1).repeat(4096,2)

You can also rely on the broadcasting rules to repeat-fill a re-sized array:

import numpy
X = numpy.random.rand(9,4)
Y = numpy.resize(X,(4096,9,4))

If you don't like the axes ordered this way, you can then transpose:

Z = Y.transpose(1,2,0)

Question is super old, but here's another option anyway:

import numpy as np
X = np.random.rand(9,4)
Y = np.dstack([X] * 4096)