pasting numpy array into bigger array

Discussion in 'Python' started by TG, Jul 26, 2006.

  1. TG

    TG Guest

    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 ?
     
    TG, Jul 26, 2006
    #1
    1. Advertising

  2. TG

    Tim Heaney Guest

    "TG" <> 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/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
     
    Tim Heaney, Jul 26, 2006
    #2
    1. Advertising

  3. TG

    TG Guest

    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
    >
     
    TG, Jul 26, 2006
    #3
  4. TG

    Robert Kern Guest

    Robert Kern, Jul 26, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. drife
    Replies:
    1
    Views:
    366
    Travis E. Oliphant
    Mar 1, 2006
  2. Replies:
    2
    Views:
    778
    Filip Larsen
    Apr 10, 2007
  3. Replies:
    2
    Views:
    491
    Robert Kern
    Nov 13, 2007
  4. Marcus
    Replies:
    25
    Views:
    1,636
    Francesco
    Aug 19, 2009
  5. Yannick Turgeon

    App getting bigger and bigger

    Yannick Turgeon, Oct 13, 2003, in forum: Perl Misc
    Replies:
    1
    Views:
    139
    Yannick Turgeon
    Oct 14, 2003
Loading...

Share This Page