本文整理汇总了Python中Matrix.Matrix.size方法的典型用法代码示例。如果您正苦于以下问题:Python Matrix.size方法的具体用法?Python Matrix.size怎么用?Python Matrix.size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Matrix.Matrix
的用法示例。
在下文中一共展示了Matrix.size方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_construction
# 需要导入模块: from Matrix import Matrix [as 别名]
# 或者: from Matrix.Matrix import size [as 别名]
def test_construction(self):
m1 = Matrix(2, 3)
self.assertEqual(m1.size(), [2, 3])
# Verify the matrix is filled with 0s
self.assertEqual(m1.data, [[0 for i in range(3)] for j in range(2)])
m2 = Matrix([0, 1, 2], [3, 4, 5], [6, 7, 8])
self.assertEqual(m2.size(), [3, 3])
# Verify the matrix has values 0-8
self.assertEqual(m2.data, [[(j * 3 + i) for i in range(3)] for j in range(3)])
示例2: test_subtraction
# 需要导入模块: from Matrix import Matrix [as 别名]
# 或者: from Matrix.Matrix import size [as 别名]
def test_subtraction(self):
m1 = Matrix(4, 4)
m2 = Matrix([0 , 1 , 2 , 3 ],
[4 , 5 , 6 , 7 ],
[8 , 9 , 10, 11],
[12, 13, 14, 15])
res = m1 - m2
m1 -= m2
self.assertEqual(res.size(), [4, 4])
self.assertEqual(res.data, [[-(j * 4 + i) for i in range(4)] for j in range(4)])
self.assertEqual(m1.data, [[-(j * 4 + i) for i in range(4)] for j in range(4)])
m3 = Matrix([4, 5, 2, 9],
[2, 1, 2, 1])
m4 = Matrix([2 , 1, 9, 11],
[12, 4, 2, 12])
r,c = m3.size()
# Data should be componenet wise addition
self.assertEqual((m3 - m4).data, [[(m3[j][i] - m4[j][i]) for i in range(c)] for j in range(r)])
m4 += 3