def test_Zeros(self):
     xRange = 2
     yRange = 4
     matrix = zeros(xRange, yRange)
     for x in range(xRange):
         for y in range(yRange):
             self.assertEqual(0, matrix[x][y])
    def test_initialize(self):
        mat_a = matrix.random(2, 3)
        mat_b = matrix.ones(2, 3)
        mat_c = matrix.zeros(2, 3)

        assert mat_a.colunm == mat_b.colunm == mat_c.colunm == 3
        assert mat_a.row == mat_b.row == mat_c.row == 2
Exemple #3
0
def loadMap(filename):
    f = open(filename)
    data = json.loads(f.read())
    cells = data['cells']
    map = zeros(data['x'], data['y'])
    for cell in cells:
        map[cell[0]][cell[1]] = 1
    return map, data['x'], data['y']
Exemple #4
0
 def ldpc_section(self):
     m = []
     # First vertical section
     # (s x k)ldpc | (s x s)identity | (s x h)zero matrix
     ldpc = self.ldpc(self.k, self.s)
     identity = matrix.identity(self.s)
     zero = matrix.zeros(self.s, self.h)
     for i in xrange(self.s):
         m.append(ldpc[i] + identity[i] + zero[i])
     return m
Exemple #5
0
 def ldpc_section(self):
     m = []
     # First vertical section
     # (s x k)ldpc | (s x s)identity | (s x h)zero matrix
     ldpc = self.ldpc(self.k, self.s)
     identity = matrix.identity(self.s)
     zero = matrix.zeros(self.s, self.h)
     for i in xrange(self.s):
         m.append(ldpc[i] + identity[i] + zero[i])
     return m
def calculateNewMap(map):
    newMap = zeros(len(map[0]), len(map))
    for x in range(len(newMap)):
        for y in range(len(newMap[0])):
            count = countNeighbours(map, x, y)
            if map[x][y] == 1:
                if count < 2 or count > 3:
                    newMap[x][y] = 0
                else:
                    newMap[x][y] = 1
            else:
                if count == 3:
                    newMap[x][y] = 1
    return newMap
    def test_zeros(self):
        """
        Test the zeros matrix method
        """
        rows = 5
        columns = 10
        # Get 5 rows of 10 bits
        m = matrix.zeros(rows, columns)

        # Make sure we have rows rows
        self.assertTrue(len(m) == rows)

        for row in xrange(rows):
            # Make sure each row has columns bits
            self.assertTrue(len(m[row]) == columns)

            # Make sure each bit in row row is 0(False)
            for i in xrange(columns):
                self.assertTrue(m[row][i] is False)