本文整理汇总了Python中Matrix.Matrix.transposed方法的典型用法代码示例。如果您正苦于以下问题:Python Matrix.transposed方法的具体用法?Python Matrix.transposed怎么用?Python Matrix.transposed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Matrix.Matrix
的用法示例。
在下文中一共展示了Matrix.transposed方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_multplication
# 需要导入模块: from Matrix import Matrix [as 别名]
# 或者: from Matrix.Matrix import transposed [as 别名]
def test_multplication(self):
# Test dot products
# Row vectors
v1 = Matrix([1, 2])
v2 = Matrix([5], [6])
self.assertEqual(v1 * v2, 17)
self.assertEqual(v1 * [5, 6], 17)
# Column vectors
v1 = Matrix([10], [7])
v2 = Matrix([5 ], [8])
self.assertEqual(v1 * v2.transposed(), Matrix([50, 80], [35, 56]))
# Test matrix scalar multiplication
m = Matrix([1, 4, 5, 6], [3, 8, 9, 2], [9, 12, 4, 13])
self.assertEqual((m * 4).data, [[(m[j][i] * 4) for i in range(m.cols)] for j in range(m.rows)])
# Test matrix multiplication
m1 = Matrix([2, 3], [4, 5], [6, 7])
m2 = Matrix([1, 2, 3], [4, 5, 6])
r = Matrix([14, 19, 24], [24, 33, 42], [34, 47, 60])
self.assertEqual(m1 * m2, r)
self.assertEqual(m1 * [[1, 2, 3], [4, 5, 6]], r)
# Test swapping rows of a matrix with a permutation matrix
m = Matrix([11, 9 , 24, 2],
[1 , 5 , 2 , 6],
[3 , 17, 18, 1],
[2 , 5 , 7 , 1])
p = Matrix([1, 0, 0, 0],
[0, 0, 1, 0],
[0, 0, 0, 1],
[0, 1, 0, 0])
self.assertEqual(p * m, Matrix(
[11, 9 , 24, 2],
[3 , 17, 18, 1],
[2 , 5 , 7 , 1],
[1 , 5 , 2 , 6]))
# Test swapping of cols of a matrix with the same permutation matrix
self.assertEqual(m * p, Matrix(
[11, 2, 9 , 24 ],
[1 , 6, 5 , 2 ],
[3 , 1, 17, 18 ],
[2 , 1, 5 , 7 ]))
# Multiplication of matrix with a matrix of 3 columns and list of 3 components
self.assertEqual(
Matrix([24 , 1, 8 ],
[6 , 0, 2 ],
[-12, 1, -3]) * Matrix([1], [9], [-2]),
Matrix([17], [2], [3]))
self.assertEqual(
Matrix([24 , 1, 8 ],
[6 , 0, 2 ],
[-12, 1, -3]) * [1, 9, -2],
Matrix([17], [2], [3]))
示例2: test_transpose
# 需要导入模块: from Matrix import Matrix [as 别名]
# 或者: from Matrix.Matrix import transposed [as 别名]
def test_transpose(self):
m = Matrix([1, 2, 3], [4, 5, 6])
r = Matrix([1, 4], [2, 5], [3, 6])
self.assertEqual(m.transposed(), r)