Question: how do I flatten this list:

```
irr_list = [[[u'Animal Collective'], u'Lion in a Coma'], [[u'Animal Collective'], u'Hocus Pocus'], [[u'Animal Collective'], u'Vertical'], [[u'Animal Collective'], u'Natural Selection'], [[u'Animal Collective'], u'Spilling Guts'], [[u'Animal Collective'], u'Recycling']]

```

for this desired output?

```
output = [[u'Animal Collective', u'Lion in a Coma'], [u'Animal Collective', u'Hocus Pocus'], [u'Animal Collective', u'Vertical'], [u'Animal Collective', u'Natural Selection'], [u'Animal Collective', u'Spilling Guts'], [u'Animal Collective', u'Recycling']]

```

I have tried :

```
flattened = [val for sublist in irr_list for val in sublist]

```

to no avail

Answer: 
You can use `as_strided` for this pretty efficiently I think.

```
def window_nd(a, window, steps = None):
    ashp = np.array(a.shape)
    wshp = np.array(window).reshape(-1)
    if steps:
        stp = np.array(steps).reshape(-1)
    else:
        stp = np.ones_like(ashp)
    astr = np.array(a.strides)
    assert np.all(np.r_[ashp.size == wshp.size, wshp.size == stp.size, wshp <= ashp])
    shape = tuple((ashp - wshp) // stp + 1) + tuple(wshp)
    strides = tuple(astr * stp) + tuple(astr)
    as_strided = np.lib.stride_tricks.as_strided
    aview = as_strided(a, shape = shape, strides = strides)
    return aview

```

**EDIT:** Generalizing the striding method as much as I can.

For your specific question:

```
aview = window_nd(a, (288, 288), (144, 144))
z = aview.copy().reshape(-1, wx, wy) #to match expected output
print(z.shape, z.dtype) # z.shape should be (num_patches, 288, 288)

```
If you do not mind using ImageMagick, then it is trivial using the -crop command. See <https://imagemagick.org/Usage/crop/#crop_tile>

You can call imagemagick using Python subprocess call.

Input:

[![enter image description here](https://i.stack.imgur.com/95BEv.png)](https://i.stack.imgur.com/95BEv.png)

Lets say you want 4 256x256 tiles for simplicity.

```
convert lena512.png -crop 256x256 lena512_%d.png

```

or by percent

```
convert lena512.png -crop 50x50% lena512_%d.png

```

[![enter image description here](https://i.stack.imgur.com/fs1MO.png)](https://i.stack.imgur.com/fs1MO.png)

[![enter image description here](https://i.stack.imgur.com/TAUxs.png)](https://i.stack.imgur.com/TAUxs.png)

[![enter image description here](https://i.stack.imgur.com/UKpmm.png)](https://i.stack.imgur.com/UKpmm.png)

[![enter image description here](https://i.stack.imgur.com/tRx24.png)](https://i.stack.imgur.com/tRx24.png)