User Profile

Collapse

Profile Sidebar

Collapse
cLoque
cLoque
Last Activity: Nov 11 '07, 11:33 PM
Joined: Nov 5 '07
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • cLoque
    replied to help with addition of dictionary values
    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...
    See more | Go to post

    Leave a comment:


  • cLoque
    replied to What is your OS and Python Version
    Windows Vista Home Premium

    Python Version 2.5.1 Tk version 8.4 IDLE Version 1.2.1
    See more | Go to post

    Leave a comment:


  • cLoque
    replied to help with addition of dictionary values
    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,
    ...
    See more | Go to post

    Leave a comment:


  • cLoque
    replied to help with addition of dictionary values
    [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,...
    See more | Go to post
    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:


  • cLoque
    replied to help with addition of dictionary values
    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():
    ...
    See more | Go to post

    Leave a comment:


  • cLoque
    replied to help with addition of dictionary values
    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

    ...
    See more | Go to post

    Leave a comment:


  • cLoque
    started a topic help with addition of dictionary values

    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]
    ...
    See more | Go to post

  • 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,
    ...
    See more | Go to post

    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...
    See more | Go to post

    Leave a comment:


  • cLoque
    started a topic How To Create A Dictionary Based - Sparse Matrix

    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):
    See more | Go to post
No activity results to display
Show More
Working...