I'm trying to use the map Python function (I know I can use list comprehension but I was instructed to use map in this example) to take the row average of a two row matrix.
Here is what I think the answer should look like:
def average_rows2(mat):
print( map( float(sum) / len , [mat[0],mat[1]] ) )
average_rows2([[4, 5, 2, 8], [3, 9, 6, 7]])
Right now, only the sum function works:
def average_rows2(mat):
print( map( sum , [mat[0],mat[1]] ) )
average_rows2([[4, 5, 2, 8], [3, 9, 6, 7]])
The first problem is that adding the float() to the sum function gives the error:
TypeError: float() argument must be a string or a number
Which is weird because the elements of the resulting list should be integers since it successfully calculates the sum.
Also, adding / len to the sum function gives this error:
TypeError: unsupported operand type(s) for /: 'builtin_function_or_method' and 'builtin_function_or_method'
For this error, I tried * and // and it says that none are supported operand types. I don't understand why none of these would be supported.
Maybe this means that the map function doesn't take composite functions?