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. -
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
-
I get the same error form this function: -
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
-
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
7 1899 bartonc 6,596
Recognized Expert Expert
I don't see why you are calling map() in a loop. map() goes through the iterable and returns an iterable with each element passed to and return from func:
>>> def func1(data):
... return data + 1
...
>>> aList = [1,2,3,4]
>>> map(func1, aList)
[2, 3, 4, 5]
>>>
That was a good point, and i have changed the code so that the loop is no longer included, but i still get the same error.
now then code looks like: -
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)
-
b = map(function,b)
-
b = array(b)
-
b = matrix(b)
-
b = b.T
-
return b
-
but again, the error persists
how did you call these 2 functions. show the whole script.
here it is: -
def main(file_name):
-
global i, max_lag, max_var, min_var, semivariogramz, w
-
w = [0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1]
-
f = open(file_name,'r')
-
data = tabfile_to_listnest(f) # returns nested list
-
f.close
-
semivariogramz = semivar(data) # returns nested list
-
i = len(semivariogramz) - 1
-
max_lag = semivariogramz[i][0]
-
max_var = semivariogramz[i][1]
-
min_var = semivariogramz[0][1]
-
F = [f0,f1,f2,f3,f4,f5,f6,f7,f8,f9] # f0...f9 defined elsewhere
-
A_list = b_list = F
-
for m in range(len(data)):
-
target = data[m]
-
-
for n in range(10):
-
A_list[n] = A_maker(data,F[n])
-
b_list[n] = b_maker(data,target,F[n])
-
-
-
-
def A_maker(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)
-
A = map(function,A)
-
for k in range(len(A)):
-
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)
-
return A
-
-
-
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)
-
-
b = map(function,b)
-
b = array(b)
-
b = matrix(b)
-
return b
-
here it is: -
def main(file_name):
-
global i, max_lag, max_var, min_var, semivariogramz, w
-
w = [0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1]
-
f = open(file_name,'r')
-
data = tabfile_to_listnest(f) # returns nested list
-
f.close
-
semivariogramz = semivar(data) # returns nested list
-
i = len(semivariogramz) - 1
-
max_lag = semivariogramz[i][0]
-
max_var = semivariogramz[i][1]
-
min_var = semivariogramz[0][1]
-
F = [f0,f1,f2,f3,f4,f5,f6,f7,f8,f9] # f0...f9 defined elsewhere
-
A_list = b_list = F
-
for m in range(len(data)):
-
target = data[m]
-
-
for n in range(10):
-
A_list[n] = A_maker(data,F[n])
-
b_list[n] = b_maker(data,target,F[n])
-
-
-
-
def A_maker(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)
-
A = map(function,A)
-
for k in range(len(A)):
-
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)
-
return A
-
-
-
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)
-
-
b = map(function,b)
-
b = array(b)
-
b = matrix(b)
-
return b
-
this -
A_list[n] = A_maker(data,F[n])
-
is the problem. you are passing in a list F[n] to map() as the first argument which should be a function.
[/code]
this -
A_list[n] = A_maker(data,F[n])
-
is the problem. you are passing in a list F[n] to map() as the first argument which should be a function.
[/code]
But F[] is a list of functions. f0...f9 are defined elsewhere and F looks like: -
F = [f0,f1,f2,f3,f4,f5,f6,f7,f8,f9]
-
But F[] is a list of functions. f0...f9 are defined elsewhere and F looks like: -
F = [f0,f1,f2,f3,f4,f5,f6,f7,f8,f9]
-
if its a list of functions, then you have to call map on each of them individually. use a for loop to go through every item in this list and pass to A_maker
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Erlend Fuglum |
last post by:
Hi everyone,
I'm having some trouble sorting lists. I suspect this might have
something to do with locale settings and/or character
encoding/unicode.
Consider the following example, text...
|
by: naruto |
last post by:
Hi all,
I have the following being defined in a A.cxx file.
// define in source file. Not exported to the outside world (this
cannot be
// moved to the header file )
#define CHANNEL_0 0...
|
by: Falc2199 |
last post by:
Hi,
Does anyone know how to make this work?
var sectionId = 5;
repeat_section_sectionId();
function repeat_section_5(){
alert("firing");
}
|
by: free2klim |
last post by:
Hi,
I am relatively new to programming C++ and I am writing a small program
in which I am using a 3D array of type int. The 3D array is a member
of class GameBoard, which I have defined in the...
|
by: rengaraj |
last post by:
JBoss version:4.0.4
Hibernate version:3.2
Database:Oracle10g
Hi. I am facing an entity mapping problem. I have an Oracle stored function which takes as a parameter an Oracle array and returns a...
|
by: 4Ankit |
last post by:
hey guys i am having trouble changing my array code to include a 'for/
in' structure
the code i am trying to change is below:
<script type="text/javascript">
var contents = new Array(3)
|
by: Nathan Sokalski |
last post by:
I am trying to use the System.Array.ForEach method in VB.NET. The action
that I want to perform on each of the Array values is:
Private Function AddQuotes(ByVal value As String) As String
Return...
|
by: jthep |
last post by:
Hi,
I'm trying to get user input for a record book but I'm having trouble as I think I'm not making the getline function read the buffer correctly. I have the following variables declared in...
|
by: matheussousuke |
last post by:
Hello, I'm using tiny MCE plugin on my oscommerce and it is inserting my website URL when I use insert image function in the emails.
The goal is: Make it send the email with the URL...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |