Python Forum
2D array element Calculation
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
2D array element Calculation
#1
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.
Reply


Messages In This Thread
2D array element Calculation - by poonck1 - Mar-02-2017, 03:32 PM
RE: 2D array element Calculation - by wavic - Mar-02-2017, 03:54 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  ValueError: setting an array element with a sequence ying9309 2 7,715 Jul-15-2018, 07:04 AM
Last Post: ying9309
  Call out data from 2D array to perform calculation poonck1 1 3,325 Feb-28-2017, 01:53 PM
Last Post: buran
  How to increase speed of access element in 2 dimension array? Diver 6 6,106 Nov-03-2016, 03:42 AM
Last Post: Diver

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020