Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Trying to make a Matrix of nodes in Python

Name: Anonymous 2013-10-10 20:03

Hey /prog/rammers, I'm trying to make a Matrix of nodes in python.
so far I have a node class that reads as such:

class Node (object) :
   
    def __init__(self, value):
        self.north = None
        self.east = None
        self.south = None
        self.west = None
        self.value = value
       
    def getNorth(self):
        return self.north
       
    def getSouth(self):
        return self.south
       
    def getEast(self):
        return self.east
       
    def getWest(self):
        return self.west
       
    def getValue(self):
        return self.value


And a LinkedMatrix class that reads like this:

class LinkedMatrix(object):
   
    def __init__(self, x, y, defaultValue):
       
        ''' create a new matrix with x columns and y rows
        with default value default value'''
       
        self._xRows = x
        # x amt of rows
        self._yCols = y
        # y amt of columns
       
        base_node=Node(defaultValue)
        self.head = Node(defaultValue)
       
        self.mlist = []
        self.head.east=base_node
        self.mlist = [self.head]
        for number in range(self._yCols):
            base_node.east=Node(defaultValue)
            self.mlist = self.mlist + [base_node]
       
     
     
       
       
       
 Im thinking I should make a list of the nodes in python and then make a list of lists, but Im having trouble wording my code so that the nodes properly connect to each other, and I also am wondering how I can make their connections (north and south) work across different lists.

Help is very needed and would be very appreciated.

Name: Anonymous 2013-10-10 20:58

Making progress...
I made a for loop inside a for loop that properly nests the nodes in the matrix and makes many different nodes at different points in memory

Now I need to figure out how to make a __str__ definition that will give a proper string representation instead of showing where the nodes are located in memory


 for number in range(self._xRows) :
            self.mlist = [] #empty list meant to contain future nodes
            for number in range (self._yCols) :
                base_node=Node(defaultValue)
                self.mlist = self.mlist + [base_node]
            self.matrix = self.matrix +[self.mlist]

Name: YHWH 2013-10-10 21:03

Thou shalt not use Python.

Name: Anonymous 2013-10-10 21:08

LETS FUCKING GO!!!!!!!


 def __str__ (self):
       
        '''returns the string representation of the matrix'''

        stringmatrix=[]
        for item in self.matrix:
            stringmlist=[]
            for node in item:
                a=str(node.getValue())
                stringmlist=stringmlist+[a]
            stringmatrix = stringmatrix + [stringmlist]
        for item in stringmatrix:
            print (item)
       
        return ''
   
IM BALLIN OUT HERE, /prog/!
IM NEW TO THIS PROGRAMMING SHIT BUT GIVE ME TIME
IM ABOUT TO BECOME A MASTER

Name: Anonymous 2013-10-10 21:10

>>3
Im forced to use it for my class. The worst part with this project isnt even using python. Its that there are built in lists and making a matrix could be so much easier than what Im doing with these damn nodes.

Name: Anonymous 2013-10-10 21:15

read sicp

Name: Anonymous 2013-10-10 21:21

>>6
is there anything about linked matrices in there? Or is it just the basic linked list ?

Name: Anonymous 2013-10-10 21:29

Terrible !

Name: Anonymous 2013-10-10 21:39

>>8
My nose has no dog. Then how does he exist? Terrible!

Name: Anonymous 2013-10-10 21:45

>>8
>>9
I dont understand what you're trying to say here

Name: Anonymous 2013-10-10 21:47

>>10
He means "go the fuck back to /g/"

Name: Anonymous 2013-10-10 21:58

>>11
but this is programming

Name: Anonymous 2013-10-10 22:03

>>12
This is /home/work, not /prog/ramming. Go back to /home/.

Name: Anonymous 2013-10-10 23:12

>>13
You guys arent even helping me, Im just documenting this shit

also

def __getitem__(self, index):
        '''return the element at the index expressed as a tuple'''
        x,y = index
        #return "fetching %s, %s" % (x, y)
        stringmatrix=[]
        for item in self.matrix:
            stringmlist=[]
            for node in item:
                a= str(node.getValue())
                stringmlist=stringmlist+[a]
            stringmatrix = stringmatrix + [stringmlist]
        get = stringmatrix[x][y]
        print (get)

Name: Anonymous 2013-10-11 1:25

>>11
>le pedophile sage

Name: HAXUS THE PEDOHPILE SAGE 2013-10-11 7:09

HAXUS THE PEDOPHILE SAGE

Name: Anonymous 2013-10-11 9:30

>>16
>le haxus the pedophile sage

Name: Anonymous 2013-10-11 14:05

Seems like you need a graph.

Don't change these.
Name: Email:
Entire Thread Thread List