splitting numpy array unevenly

Discussion in 'Python' started by Wanderer, Sep 17, 2012.

  1. Wanderer

    Wanderer Guest

    I need to divide a 512x512 image array with the first horizontal and vertical division 49 pixels in. Then every 59 pixels in after that. hsplit and vsplit want to start at the edges and create a bunch of same size arrays. Is there a command to chop off different sized arrays?

    Thanks
     
    Wanderer, Sep 17, 2012
    #1
    1. Advertising

  2. On Tuesday, September 18, 2012 8:31:09 AM UTC+10, Wanderer wrote:
    > I need to divide a 512x512 image array with the first horizontal and vertical division 49 pixels in. Then every 59 pixels in after that. hsplit and vsplit want to start at the edges and create a bunch of same size arrays. Is there a command to chop off different sized arrays?
    >
    >
    >
    > Thanks


    I don't know that I follow completely, but can't you just slice what you are after?

    x = np.random.rand(512*512).reshape(512,512)
    xx = x[0,:49]
    And put the rest of the slices in a loop...?
     
    Martin De Kauwe, Sep 18, 2012
    #2
    1. Advertising

  3. Wanderer

    Wanderer Guest

    On Monday, September 17, 2012 7:43:06 PM UTC-4, Martin De Kauwe wrote:
    > On Tuesday, September 18, 2012 8:31:09 AM UTC+10, Wanderer wrote:
    >
    > > I need to divide a 512x512 image array with the first horizontal and vertical division 49 pixels in. Then every 59 pixels in after that. hsplit and vsplit want to start at the edges and create a bunch of same size arrays.Is there a command to chop off different sized arrays?

    >
    > >

    >
    > >

    >
    > >

    >
    > > Thanks

    >
    >
    >
    > I don't know that I follow completely, but can't you just slice what you are after?
    >
    >
    >
    > x = np.random.rand(512*512).reshape(512,512)
    >
    > xx = x[0,:49]
    >
    > And put the rest of the slices in a loop...?


    I was trying to avoid the loop. I figured it out. hsplit and vsplit will work. I just need to give it a list of break points. I still need a loop though.

    breakPoints = range(49,512,59)
    rowArrays = hsplit(InputArray, breakPoints)
    OutArrays = []
    for r in rowArrays:
    OutArrays.append(vsplit(r, breakPoints))
     
    Wanderer, Sep 18, 2012
    #3
  4. Wanderer

    Hans Mulder Guest

    On 18/09/12 16:02:02, Wanderer wrote:
    > On Monday, September 17, 2012 7:43:06 PM UTC-4, Martin De Kauwe wrote:
    >> On Tuesday, September 18, 2012 8:31:09 AM UTC+10, Wanderer wrote:
    >>> I need to divide a 512x512 image array with the first horizontal
    >>> and vertical division 49 pixels in. Then every 59 pixels in after
    >>> that. hsplit and vsplit want to start at the edges and create a
    >>> bunch of same size arrays. Is there a command to chop off
    >>> different sized arrays?


    >> I don't know that I follow completely, but can't you just slice
    >> what you are after?


    >> x = np.random.rand(512*512).reshape(512,512)
    >> xx = x[0,:49]


    >> And put the rest of the slices in a loop...?


    > I was trying to avoid the loop. I figured it out. hsplit and vsplit
    > will work. I just need to give it a list of break points. I still
    > need a loop though.


    > breakPoints = range(49,512,59)
    > rowArrays = hsplit(InputArray, breakPoints)
    > OutArrays = []
    > for r in rowArrays:
    > OutArrays.append(vsplit(r, breakPoints))


    How about a list display:

    breakPoints = range(49,512,59)
    rowArrays = hsplit(InputArray, breakPoints)
    OutArrays = [vsplit(r, breakPoints) for r in rowArrays]

    In some sense, it's still a loop, but at least it doesn't look like one.


    Hope this helps,

    -- HansM
     
    Hans Mulder, Sep 19, 2012
    #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:
    379
    Travis E. Oliphant
    Mar 1, 2006
  2. Duncan Smith
    Replies:
    3
    Views:
    431
    Duncan Smith
    Apr 25, 2007
  3. Replies:
    2
    Views:
    500
    Robert Kern
    Nov 13, 2007
  4. W. eWatson
    Replies:
    2
    Views:
    971
    W. eWatson
    Nov 23, 2009
  5. Tom Kacvinsky

    Installing numpy over an older numpy

    Tom Kacvinsky, Jun 15, 2012, in forum: Python
    Replies:
    1
    Views:
    363
    Miki Tebeka
    Jun 15, 2012
Loading...

Share This Page