コード例 #1
0
 def testSubtraction(self):
     """
     The binary subtraction operator
     should, when applied to two matricies, product
     the difference of the two matricies if and only if
     their dimensions are equal.
     """
     A = Matrix.fromArray([
         [0,2,3],
         [4,2,6],
         [4,5,6]
     ])
     B = Matrix.fromArray([
         [4, 9, 6],
         [7, 8, 1],
         [0, 13,2]
     ])
     C = Matrix.fromArray([
         [1,2,3],
         [4,5,6]
     ])
     diffAB = Matrix.fromArray([
         [-4, -7, -3],
         [-3, -6, 5],
         [4, -8, 4]
     ])
     self.assertEqual(A - B, diffAB)
     self.assertEqual(A - C, None)
コード例 #2
0
    def testAddition(self):
        """
        The binary addition operator
        should, when applied to two matricies, product
        the sum of the two matricies if and only if
        their dimensions are equal.
        """

        A = Matrix.fromArray([
            [0,2,3],
            [4,2,6],
            [4,5,6]
        ])
        B = Matrix.fromArray([
            [4, 9, 6],
            [7, 8, 1],
            [0, 13,2]
        ])
        C = Matrix.fromArray([
            [1,2,3],
            [4,5,6]
        ])
        sumAB = Matrix.fromArray([
            [4, 11, 9],
            [11, 10, 7],
            [4, 18, 8]
        ])
        self.assertEqual(A + B, sumAB)
        self.assertEqual(A + C, None)
コード例 #3
0
 def setUp(self):
     self.matrix = Matrix.fromArray([
         [1, 2, 3],
         [4, 5, 6],
         [7, 8, 9]
     ])
     self.identity = Matrix.fromArray([
         [1, 0, 0],
         [0, 1, 0],
         [0, 0, 1]
     ])
コード例 #4
0
    def testMultiply(self):
        """
        The binary multiplication operator
        should, when applied to two matricies, produce
        the matrix product if and only if the number of rows in the left
        operand is equal to the number of columns in the right operand.

        Matrix multiplication is generally not communitive, so
        the product AB should differ from the product BA (usually)
        """
        matrixA = self.matrix
        matrixB = self.matrix.transpose()

        productAB = matrixA * matrixB
        productBA = matrixB * matrixA

        self.assertEqual(productAB, [
            [14,32,50],
            [32,77,122],
            [50,122,194]
        ])

        self.assertEqual(productBA, [
            [66,78,90],
            [78,93,108],
            [90,108,126]
        ])

        matrixC = Matrix.fromArray([
            [1,2,3],
            [4,5,6]
        ])

        self.assertEqual(matrixA * matrixC, None)
コード例 #5
0
    def testTranspose(self):
        """
        The transpose method return a copy of the matrix
        with the columns and rows exchanged.
        """

        transpose = Matrix.fromArray([
            [1, 4, 7],
            [2, 5, 8],
            [3, 6, 9]
        ])
        self.assertEqual(self.matrix.transpose(), transpose)
コード例 #6
0
    def testDeterminant(self):
        """
        The determinant method should return None if the
        matrix is not square. It should return zero
        if the matrix is singular.
        """

        nonSquare = Matrix.fromArray([
            [1,2,3],
            [4,5,6]
        ])
        singularMatrix = self.matrix
        self.assertEqual(nonSquare.determinant(), None)
        self.assertEqual(singularMatrix.determinant(), 0)
コード例 #7
0
def computeDeterminant(model):
    request.det = Matrix.fromArray(model['matrix']).determinant()
コード例 #8
0
def buildMatricies(model):
    request.matrixA = Matrix.fromArray(model['lvalue'])
    request.matrixB = Matrix.fromArray(model['rvalue'])
コード例 #9
0
def computeDeterminant(model):
    request.det = Matrix.fromArray(model['matrix']).determinant()
コード例 #10
0
ファイル: add.py プロジェクト: ben-hunter-hansen/matrix-api
def buildMatricies(model):
    request.matrixA = Matrix.fromArray(model['lvalue'])
    request.matrixB = Matrix.fromArray(model['rvalue'])
コード例 #11
0
 def testDimension(self):
     matrix = Matrix.fromArray([[1, 2, 3], [4, 5, 6]])
     self.assertEqual(util.dimension(matrix), (3, 2))
コード例 #12
0
 def testDimension(self):
     matrix = Matrix.fromArray([
         [1,2,3],
         [4,5,6]
     ])
     self.assertEqual(util.dimension(matrix), (3,2))