Ha! I knew it had to be possible! Thanks Derek. So for and N = 2 (now on my
laptop):
In [70]: M = 1200
In [69]: N = 2
In [71]: a = np.random.randint(0, 255, (M**2)).reshape(M,-1)
In [76]: timeit np.rollaxis(np.tile(a, N**2).reshape(M,N,-1), 2,
1).reshape(M*N,-1)
10 loops, best of 3: 99.1 ms per
On 03.12.2011, at 6:47PM, Olivier Delalleau wrote:
> Ah sorry, I hadn't read carefully enough what you were trying to achieve. I
> think the double repeat solution looks like your best option then.
Considering that it is a lot shorter than fixing the tile() result, you
are probably right (I've
On 03.12.2011, at 6:22PM, Robin Kraft wrote:
> That does repeat the elements, but doesn't get them into the desired order.
>
> In [4]: print a
> [[1 2]
> [3 4]]
>
> In [7]: np.tile(a, 4)
> Out[7]:
> array([[1, 2, 1, 2, 1, 2, 1, 2],
>[3, 4, 3, 4, 3, 4, 3, 4]])
>
> In [8]: np.tile(a, 4)
Ah sorry, I hadn't read carefully enough what you were trying to achieve. I
think the double repeat solution looks like your best option then.
-=- Olivier
2011/12/3 Robin Kraft
> That does repeat the elements, but doesn't get them into the desired order.
>
> In [4]: print a
> [[1 2]
> [3 4]]
>
That does repeat the elements, but doesn't get them into the desired order.
In [4]: print a
[[1 2]
[3 4]]
In [7]: np.tile(a, 4)
Out[7]:
array([[1, 2, 1, 2, 1, 2, 1, 2],
[3, 4, 3, 4, 3, 4, 3, 4]])
In [8]: np.tile(a, 4).reshape(4,4)
Out[8]:
array([[1, 2, 1, 2],
[1, 2, 1, 2],
You can also use numpy.tile
-=- Olivier
2011/12/3 Robin Kraft
> Thanks Warren, this is great, and even handles giant arrays just fine if
> you've got enough RAM.
>
> I also just found this StackOverflow post with another solution.
>
> a.repeat(2, axis=0).repeat(2, axis=1).
> http://stackoverflo
Thanks Warren, this is great, and even handles giant arrays just fine if you've
got enough RAM.
I also just found this StackOverflow post with another solution.
a.repeat(2, axis=0).repeat(2, axis=1).
http://stackoverflow.com/questions/7525214/how-to-scale-a-numpy-array
np.kron lets you do more
On Sat, Dec 3, 2011 at 12:35 AM, Robin Kraft 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
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 so