Python Forum

Full Version: 2D array element Calculation
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have an array to do some calculation for each element, which looks like this:
a = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
My expected results is as follow after calculation:
a_1 = [[2, 6, 3], [5, 12, 6], [8, 18, 9]]

I wrote the following lines:
f = 1
g = 2
a_1 = [c +f, (d+f)*g, e for (c, d, e) in array]
However it is error message like this:
Error:
SyntaxError: invalid syntax
How to amend the code to get the results I want? One more requirement is I don't want to use NumPy.
Hello!
c_1 = [[c + f, (d + f)*g, e] for c, d, e in a]
Post the full error traceback next time please