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 1916 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 containing norwegian special
characters æ, ø and å.
>>> liste =
|
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
#define CHANNEL_1 1
#define CHANNEL_2 2
|
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 GameBoard.h header file
as follows:
class GameBoard {
//function prototypes
public:
|
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 refcursor. And I want to map the returning result to an entity class. I have created the entity class as follows:
@Entity
@SqlResultSetMapping(name = "flightBaggageSummaryMapping",
entities = @EntityResult(entityClass =...
| |
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 String.Format("'{0}'", value)
End Function
Basically, I just want to surround each value with single quotes. However, I
am having trouble getting this to work using the System.Array.ForEach
method. This may be partially because I am not very...
|
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 main:
char name, address, telno, input;
int yearofbirth, choice, records;
yearofbirth = 0;
choice = -1;
Then here's part of the code where it goes wrong:
|
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 http://mghospedagem.com/images/controlpanel.jpg
instead of
http://mghospedagem.comhttp://mghospedagem.com/images/controlpanel.jpg
As u see, there's the website URL before the image URL.
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |