I'm trying to create an ASCII photo generator in python by following a guide online, so what I did was I converted the image date to RGB tuples and put them in a 2d array. I converted this 2d array to a brightness array by taking the average of all RGB values. But this brightness array shows different output when I print it again compared to printing it while assigning the values.
Initially it shows the correct output, but when I print it again it shows the same values in all the rows of the matrix.
from PIL import Image
import math
im = Image.open("smallimage.jpg")
print(im.size)
rows,cols = (im.size[0],im.size[1])
print(rows,cols)
arr = [[0]*cols]*rows
arr = list(im.getdata())
arr = [arr[i*cols: (i+1)*cols] for i in range(rows)]
brightness_matrix = [[0]*cols]*rows
for row in range(rows):
for col in range(cols):
brightness_matrix[row][col] = math.floor((arr[row][col][0] + arr[row][col][1] + arr[row][col][2])/3)
print(brightness_matrix[row][col],end = " ")
print()
for row in range(rows):
for col in range(cols):
print(brightness_matrix[row][col],end=" ")
print()
It's the last row of the original output that keeps repeating in the new output.