I am trying to map a function to the contents of an array using the map() function. However, whenever the following function is called an error message is returned complaining that:
... line 121, in b_maker
b[k] = map(function,b[k])
TypeError: 'matrix' object is not callable
This is on a windows32 system, using python 2.5 with the numpy library.
In the following code data is a nested list of type float, target is a list of type float and function is a pre-defined function. In the first call to b_maker, where the problem occurs, function simply returns zero. I am confused because there are no matrix objects involved until after the line where the error is.
I get the same error form this function:
However the latter function is called and executes successfully many times before getting hung up and returning the error. I checked the data carefully to make sure there is not an invalid entry causing the problems, and all the functions being passed as the parameter function are fine. I am baffled.
This is semi-urgent because it is part of a project that must be finished in three days. Thank you
... line 121, in b_maker
b[k] = map(function,b[k])
TypeError: 'matrix' object is not callable
This is on a windows32 system, using python 2.5 with the numpy library.
In the following code data is a nested list of type float, target is a list of type float and function is a pre-defined function. In the first call to b_maker, where the problem occurs, function simply returns zero. I am confused because there are no matrix objects involved until after the line where the error is.
Code:
def b_maker(data,target,function):
b = ones((len(data)+1,1),float)
for m in range(len(data)):
b[m] = sqrt((data[m][0] - target[0])**2 + (data[m][1] - target[1])**2)
for k in range(len(b)-1):
b[k] = map(function,b[k]) ##### <--Problem is here
b = array(b)
b = matrix(b)
b = b.T
return b
Code:
def A_inverse(data,function):
A = zeros((len(data),len(data)+1),float)
for m in range(len(data)):
for n in range(len(data)):
A[m,n] = distance_in_data(data,m,n)
for k in range(len(A)):
A[k] = map(function,A[k]) ## <----Problem occurs here
A[k][k] =0.0
for k in range(len(A)):
A[len(A)-1][k] = 1.0
A[len(A)-1][len(A)] = 0.0
A = array(A)
A = matrix(A)
A = A.I
return A
This is semi-urgent because it is part of a project that must be finished in three days. Thank you
Comment