Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   pasting numpy array into bigger array (http://www.velocityreviews.com/forums/t360555-pasting-numpy-array-into-bigger-array.html)

 TG 07-26-2006 09:59 AM

pasting numpy array into bigger array

hi.

let's say I have :

from numpy import *
x = identity(5)
y = zeros((7,7))

I want to paste x into y, starting at coordinates (1,1) in order to
change y to something like this :

0 0 0 0 0 0 0
0 1 0 0 0 0 0
0 0 1 0 0 0 0
0 0 0 1 0 0 0
0 0 0 0 1 0 0
0 0 0 0 0 1 0
0 0 0 0 0 0 0

how would you do that ?

 Tim Heaney 07-26-2006 12:24 PM

Re: pasting numpy array into bigger array

"TG" <girodt@gmail.com> writes:
>
> let's say I have :
>
> from numpy import *
> x = identity(5)
> y = zeros((7,7))
>
> I want to paste x into y, starting at coordinates (1,1) in order to
> change y to something like this :
>
> 0 0 0 0 0 0 0
> 0 1 0 0 0 0 0
> 0 0 1 0 0 0 0
> 0 0 0 1 0 0 0
> 0 0 0 0 1 0 0
> 0 0 0 0 0 1 0
> 0 0 0 0 0 0 0
>
> how would you do that ?

You can use Python slice notation for each dimension

y[1:6,1:6] = x

In general, I guess you want something like

y[1:1+x.shape[0], 1:1+x.shape[1]] = x

or

m, n = 1, 1
s, t = x.shape
y[m:m+s, n:n+t] = x

There is a mailing list for numpy

https://lists.sourceforge.net/lists/...mpy-discussion

I think it's a shame there isn't any free documentation for numpy.

Tim

 TG 07-26-2006 12:43 PM

Re: pasting numpy array into bigger array

Thanks, that's exactly what I needed.

Tim Heaney wrote:
> You can use Python slice notation for each dimension
>
> y[1:6,1:6] = x
>

 Robert Kern 07-26-2006 04:32 PM

Re: pasting numpy array into bigger array

Tim Heaney wrote:

> I think it's a shame there isn't any free documentation for numpy.

Tosh.

http://www.scipy.org/Tentative_NumPy_Tutorial
http://www.scipy.org/Numpy_Example_List
http://www.scipy.org/doc/numpy_api_docs/numpy.html

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma