2

Is it possible to use numpy.split to split a numpy.ndarray with overlapping pieces.

Example:

Given a numpy.ndarray of shape (3,3) and I want to split it into ndarray, of shape (1,1) which by

numpy.split((3,3),(1,1)) = [(1,1),(1,1),(1,1)]

But what if i wanted numpy.ndarrays of shape (3,2) , would it be able to generate a list with length 2 with overlapping numpy.ndarrays?

as such:

enter image description here

  • Could you specify what you'd like the output to look like, given an input like `np.arange(9).reshape((3, 3))`? (also: why do you want this?) My first thought would be `np.lib.index_tricks.as_strided` – mdurant Apr 09 '17 at 23:20
  • @mdurant I added an example with image. I am using overlapping as a way of generating a smooth transition between the first set, and the second set. Ps. I also corrected the wanted shape from (2,2) to (3,2)... Might have caused confusion.. –  Apr 09 '17 at 23:31
  • I've flagged my own post. found solution somewhere else. –  Apr 09 '17 at 23:40

1 Answers1

1

I am not exactly sure what you want to see, but this might answer your question:

With input:

> arr = np.arange(9, dtype='int64').reshape((3, 3))

array([[0, 1, 2],
      [3, 4, 5],
      [6, 7, 8]])


> np.lib.index_tricks.as_strided(arr, (2, 2, 2, 2), (24, 8, 24, 8), True)

array([[[[0, 1],
         [3, 4]],
        [[1, 2],
         [4, 5]]],
       [[[3, 4],
         [6, 7]],
        [[4, 5],
         [7, 8]]]])

Interestingly, there are no copies of the data here. Note that the values to as_strided are only accurate for 8-byte values and a 3x3 input. You could get them from the existing shape/strides of the input.

mdurant
  • 27,272
  • 5
  • 45
  • 74
  • could you elaborate a bit on the parameter you've entered in the function? –  Apr 09 '17 at 23:35
  • To properly parametrize, bits could be picked up from this post : http://stackoverflow.com/a/16788733/3293881 – Divakar Apr 09 '17 at 23:44