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)

```
I was not allowed to comment under the top answer from @ZdaR due to my lag of reputation. However, the code was so on point for my use case, I wanted to provide necessary changes for Python3 and Color-Channels from cv2. Thank you, @ZdaR.

This is his code adapted for Python3 with list(range()) instead of xrange() and cv2.COLOR\_BGR2RGB when reading and writing the picture. Somehow cv2 uses the channels the other way around.

```
img = cv2.cvtColor(cv2.imread("path/to/lena.png"),cv2.COLOR_BGR2RGB)
img_shape = img.shape
tile_size = (640, 640)
offset = (640, 640)

for i in list(range(int(math.ceil(img_shape[0]/(offset[1] * 1.0))))):
    for j in list(range(int(math.ceil(img_shape[1]/(offset[0] * 1.0))))):
        cropped_img = img[offset[1]*i:min(offset[1]*i+tile_size[1], img_shape[0]), offset[0]*j:min(offset[0]*j+tile_size[0], img_shape[1])]
        # Debugging the tiles
        cv2.imwrite("debug_" + str(i) + "_" + str(j) + ".png", cv2.cvtColor(cropped_img,cv2.COLOR_BGR2RGB))

```