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 went a little off while calculating the range of your for loop. The number of slices to be made, must be calculated using the offset between two slices, which is `x0/2` in your case, I have simplified your code and defined some meaningful variables which you can configure to get desired tiles from a given image:

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

```
import cv2
import math

img = cv2.imread("/path/to/lena.png") # 512x512

img_shape = img.shape
tile_size = (256, 256)
offset = (256, 256)

for i in xrange(int(math.ceil(img_shape[0]/(offset[1] * 1.0)))):
    for j in xrange(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", cropped_img)

```

As current offset if exact multiple of image dimensions, which is 512x512, hence we will get 4 tiles of same size:

[![enter image description here](https://i.stack.imgur.com/x8MGJ.png)](https://i.stack.imgur.com/x8MGJ.png) [![enter image description here](https://i.stack.imgur.com/KEBN3.png)](https://i.stack.imgur.com/KEBN3.png) [![enter image description here](https://i.stack.imgur.com/g2B2E.png)](https://i.stack.imgur.com/g2B2E.png) [![enter image description here](https://i.stack.imgur.com/Svtbg.png)](https://i.stack.imgur.com/Svtbg.png)

Changing the value of offset, would get you tiles of irregular size, if the offset if not exact multiple of the image dimensions, you may later filter those tiles if not required by changing the `math.ceil` to `math.floor` in the `for` loop.
I prefer to calculate the number of tiles beforehand and then use a simple reshape. For example

```
tile = 512
img_height = img.shape[1]
img_width = img.shape[0]
number_of_vertical_tiles = img_height // tile
number_of_horizontal_tiles = img_width // tile
cropped_img = img[:tile*number_of_vertical_tiles, :tile*number_of_horizontal_tiles,:]
tiled_img = img.reshape(-1, tile, tile, 3)

```