I have only recently started working with Python's list comprehensions. I am not comfortable with them. How would I optimise the code below by using list comprehensions?
heatmap_color = []
for r in xrange(len(heatmap)):
heatmap_color.append([])
for c in xrange(len(heatmap[r])):
heatmap_color[r].append(cmap.to_rgba(heatmap[r][c], alpha=0.5, bytes=True))
What this code does is create a 2D array (representing a colour image's pixel values). The last line maps each one of the existing grayscale pixels in heatmap to a colour with an alpha channel = 0.5 so that these can be entered in the corresponding entry in the heatmap_color array.
Currently it takes just under 30 seconds to run. I would like to reduce this time as much as possible.
Thank you!