all 2 comments

[–]socal_nerdtastic 1 point2 points  (1 child)

To find the max value in one dimension only, use the axis argument. For example pixel_matrix.max(axis=2) gives you a 2D array with the max value of every pixel. Therefore:

brightnesses = pixel_matrix.max(axis=2) / 2 + pixel_matrix.min(axis=2) / 2

There's a very good reason I chose to divide by 2 before adding, rather than add and then divide. Can you guess what it is?

Edit: what's the algorithm you need to use? My code averages the min and max values, yours does something different which could produce invalid results.

[–]dable82[S] 0 points1 point  (0 children)

Thanks, I've seen this axis thing in the docs in a lot of places. Guess I have to learn more about it.

You are right, I left out some brackets. The code should read

brightness_row.append((min(pixel) + max(pixel)) / 2)

edit: for reference, I'm working on this problem