Saturday, 15 January 2011

Adding Columns in 2D array (Python) -



Adding Columns in 2D array (Python) -

so trying add together columns of 2d array except first 2 columns of array. if sum of row greater or equal 9 , less 12, want function print row. here sample of 2d array list of lists:

[[12606.000, 74204.000, 1.000, 1.000, 1.000, 1.000, 1.000, 0.000, 0.000], [12606.000, 105492.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 1.000], [12606.000, 112151.000, 1.000, 1.000, 0.000, 0.000, 0.000, 0.000, 0.000], [12606.000, 121896.000, 0.000, 0.000, 0.000, 0.000, 0.000, 1.000, 0.000]]

(some columns deleted formatting). here code:

def sumbinrow(a): """returns list of employees recording info @ to the lowest degree 9 months , fewer twelve. """ in range(len(a)): j in range(len(a[i])): if 9 <= sum(a[i][j+2]) <12: print a[i]

i maintain getting "type error" saying 'int' object not iterable.

basically, need iterate on each list, each list, take piece of list starting 2, sum , comparison.

def sumbinrow(a): """prints list of employees recording info @ to the lowest degree 9 months , fewer twelve. """ row in a: if 9 <= sum(row[2:]) < 12: print row

or in 1 line cause why not :p

def sumbinrow(a): """prints list of employees recording info @ to the lowest degree 9 months , fewer twelve. """ print [row row in if 9 <= sum(row[2:]) < 12]

python arrays list

No comments:

Post a Comment