hi bartonc,
i tried to follow the your code. i tried to use get() before but python keeps saying that my class has no attribute get, that's why I lose hope using it. thanks for showing me how...
i tried to follow your code and this is what i end up with
[CODE=python]
def __add__(self, other):
result = GeneralSparse()
for i in range(self.row) :
for j in...
User Profile
Collapse
-
Windows Vista Home Premium
Python Version 2.5.1 Tk version 8.4 IDLE Version 1.2.1Leave a comment:
-
this is my whole program
Code:class GeneralSparse: def __init__(self, mtx={}, m=0, n=0): self.matrix = {} self.matrix.update(mtx) self.row = m self.col = n def __getitem__(self, ij): return self.matrix.get(ij,0) def __setitem__(self, ij, val): self.matrix[ij] = val def __add__(self,
Leave a comment:
-
[CODE=python]# don't forget that you may want to use print statements with your object
def __repr__(self):
return str(self.matrix )
def __getitem__(sel f, ij): # this is the syntax for calling with a tuple
return self.matrix.get (ij, 0)
def __setitem__(sel f, ij, val):
self.matrix[ij] = val # your version lacked consistance
sm_1 = sm({(0,0):5,...Last edited by bartonc; Nov 11 '07, 12:44 AM. Reason: remove quotes due to site bug: =python in opening tags only!Leave a comment:
-
hi,
before i start asking questions again, i really would like to thank this forum, slowly I was able to form my program, (especially bartonc and bvdet for wasting their time reading my pathetic questions lol), im really glad that someone is helping me...
back to my questions...
i tried to use the items() but i have error saying:
Code:line 17, in __add__ for key, value in self.items():
Leave a comment:
-
for this loop what does value means here? how can i use the one that i have set in __setitem__? does get(key, 0) gives me the value that i have set in __setitem__?
sorry if i sound confusing, but honestly i'm confused with the passing of tuples, i want to know exactly where does each value goes after using the method. am already fine with __init__ method, i'm just confused what happens to the values after setting them
...Leave a comment:
-
help with addition of dictionary values
hi,
i would like to add my two matrices, using __add__
Code:class m: def __init__(self, mtx={}, m=0, n=0): self.matrix = {} self.matrix.update(mtx) self.row = m self.col = n def __getitem__(self, ij): return self.matrix.get(ij,0) def __setitem__(self, ij, val): self.matrix[i,j]
-
Need Help in Fixing My Code
hi,
i want to hava matrix output by my code doesn't return what i want, hope you can help me with my __str__()
here it is:
Code:class GeneralSparse: def __init__(self, mtx={}, m=0, n=0): self.matrix = {} self.matrix.update(mtx) self.row = m self.col = n def __getitem__(self,
Leave a comment:
-
hi
this is what i need to figure out. it confuses me because most of the example in creating a sparse vector are in list, mine uses dictionary. i am just a beginner in python, so i really need all the help that i can get in doing this project.
hope you can help me guys
# def __init__(self, mtx={}, m=0, n=0):
The constructor takes as arguments the dictionary representation of a sparse matrix...Leave a comment:
-
How To Create A Dictionary Based - Sparse Matrix
Hi,
I would like to know how to create a dictionary based matrix. Where column and row are considered in placing my desired value. and will pass value as dictionary
just like this
def __init__(self, mtx={}, m=0, n=0):
No activity results to display
Show More
Leave a comment: