pasting numpy array into bigger array

T

TG

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 ?
 
T

Tim Heaney

TG said:
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/listinfo/numpy-discussion

You might have more luck asking your question on there.

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

Tim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,522
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top