For example I have a 2D list of 2x2 dimension stored in a variable r.
12 24
36 48
I want to divide every value in the list by 2. An easy slow way to do this is to iterate through each row and column and divide it by 2.
rows = 2
columns = 2
for x in range(rows):
for y in range(columns):
r[x][y] = r[x][y]/2
Is there an easy and fast way to divide each values in a 2D list to a specific value other than the manual approach? I tried the code below but it throws an error:
s = r /2
Error:
TypeError: unsupported operand type(s) for /: 'list' and 'int'