On Sat, Dec 3, 2011 at 12:35 AM, Robin Kraft <rkraft4@gmail.com> wrote:
I need to take an array - derived from raster GIS data - and upsample or scale it. That is, I need to repeat each value in each dimension so that, for example, a 2x2 array becomes a 4x4 array as follows:

[[1, 2],
 [3, 4]]

becomes

[[1,1,2,2],
 [1,1,2,2],
 [3,3,4,4]
 [3,3,4,4]]

It seems like some combination of np.resize or np.repeat and reshape + rollaxis would do the trick, but I'm at a loss.

Many thanks!

-Robin


Just a day or so ago, Josef Perktold showed one way of accomplishing this using numpy.kron:

In [14]: a = arange(12).reshape(3,4)

In [15]: a
Out[15]:
array([[ 0,  1,  2,  3],
       [ 4,  5,  6,  7],
       [ 8,  9, 10, 11]])

In [16]: kron(a, ones((2,2)))
Out[16]:
array([[  0.,   0.,   1.,   1.,   2.,   2.,   3.,   3.],
       [  0.,   0.,   1.,   1.,   2.,   2.,   3.,   3.],
       [  4.,   4.,   5.,   5.,   6.,   6.,   7.,   7.],
       [  4.,   4.,   5.,   5.,   6.,   6.,   7.,   7.],
       [  8.,   8.,   9.,   9.,  10.,  10.,  11.,  11.],
       [  8.,   8.,   9.,   9.,  10.,  10.,  11.,  11.]])


Warren