本文整理汇总了Python中matrix.Matrix.clear方法的典型用法代码示例。如果您正苦于以下问题:Python Matrix.clear方法的具体用法?Python Matrix.clear怎么用?Python Matrix.clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matrix.Matrix
的用法示例。
在下文中一共展示了Matrix.clear方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import clear [as 别名]
def main():
m1 = Matrix(3,2)
m2 = Matrix(3,2)
m1.clear(2)
m2.clear(3)
m3 = m1.__add__(m2)
m3 = m1.__sub__(m2)
print(type(m1))
print(type(m1._theGrid))
m3._theGrid.printArray2D()
mulTest1 = Matrix(3,2)
mulTest2 = Matrix(2,3)
mulTest1.__setitem__([0,0], 0)
mulTest1.__setitem__([0,1], 1)
mulTest1.__setitem__([1,0], 2)
mulTest1.__setitem__([1,1], 3)
mulTest1.__setitem__([2,0], 4)
mulTest1.__setitem__([2,1], 5)
mulTest1._theGrid.printArray2D()
mulTest2.__setitem__([0,0], 6)
mulTest2.__setitem__([0,1], 7)
mulTest2.__setitem__([0,2], 8)
mulTest2.__setitem__([1,0], 9)
mulTest2.__setitem__([1,1], 1)
mulTest2.__setitem__([1,2], 0)
mulTest2._theGrid.printArray2D()
mulTestRes = mulTest1.__mul__(mulTest2)
mulTestRes._theGrid.printArray2D()
mT = mulTestRes.tranpose()
mT._theGrid.printArray2D()
'''
示例2: MatrixGenericTest
# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import clear [as 别名]
class MatrixGenericTest(unittest.TestCase):
def setUp(self):
data = [
['One', 'Two', 'Three'],
['Aye', 'Bee', 'See']
]
self.matrix = Matrix(default_item, data)
def test_contains(self):
self.assertIn('Two', self.matrix)
self.assertIn('See', self.matrix)
self.assertNotIn('Fish', self.matrix)
self.assertNotIn('whoops', self.matrix)
def test_getitem(self):
self.assertEqual(self.matrix[0,1], 'Aye')
self.assertEqual(self.matrix[2,0], 'Three')
self.assertNotEqual(self.matrix[1,1], 'See')
def test_setitem(self):
newval = 'NEW!!'
self.matrix[2,1] = newval
self.assertEqual(self.matrix.data[1][2], newval)
def test_clear(self):
self.matrix.clear()
self.assertEqual(self.matrix.data, [[default_item()]])
def test_flip_orientation(self):
self.matrix.flip_orientation()
data = [
['One', 'Aye'],
['Two', 'Bee'],
['Three', 'See']
]
self.assertEqual(self.matrix.data, data)
def test_has_coord(self):
self.assertTrue(self.matrix.has_coord(1, 0))
self.assertTrue(self.matrix.has_coord(2, 1))
self.assertFalse(self.matrix.has_coord(3, 1))
def test_count_rows(self):
self.assertEqual(self.matrix.count_rows(), 2)
def test_count_cols(self):
self.assertEqual(self.matrix.count_cols(), 3)
def test_add_row(self):
newrow = [default_item()]*3
data = [
['One', 'Two', 'Three'],
newrow,
['Aye', 'Bee', 'See']
]
self.matrix.add_row(1)
self.assertEqual(self.matrix.data, data)
data = [
newrow,
['One', 'Two', 'Three'],
newrow,
['Aye', 'Bee', 'See']
]
self.matrix.add_row(0)
self.assertEqual(self.matrix.data, data)
data = [
newrow,
['One', 'Two', 'Three'],
newrow,
['Aye', 'Bee', 'See'],
newrow
]
self.matrix.add_row()
self.assertEqual(self.matrix.data, data)
def test_add_col(self):
data = [
['One', default_item(), 'Two', 'Three'],
['Aye', default_item(), 'Bee', 'See']
]
self.matrix.add_col(1)
self.assertEqual(self.matrix.data, data)
data = [
[default_item(), 'One', default_item(), 'Two', 'Three'],
[default_item(), 'Aye', default_item(), 'Bee', 'See']
]
self.matrix.add_col(0)
self.assertEqual(self.matrix.data, data)
data = [
[default_item(), 'One', default_item(), 'Two', 'Three', default_item()],
[default_item(), 'Aye', default_item(), 'Bee', 'See', default_item()]
]
self.matrix.add_col()
self.assertEqual(self.matrix.data, data)
def test_remove_row(self):
data = [
['One', 'Two', 'Three']
]
#.........这里部分代码省略.........
示例3: Scene
# 需要导入模块: from matrix import Matrix [as 别名]
# 或者: from matrix.Matrix import clear [as 别名]
#.........这里部分代码省略.........
self.error('Invalid row')
return
self.add_undo('rr', (pos, self.grid.row(pos)))
self.grid.remove_row(pos)
else:
if (pos,0) not in self.grid:
self.error('Invalid column')
return
self.add_undo('rc', (pos, self.grid.col(pos)))
self.grid.remove_col(pos)
self.draw_scene()
# ======== CELLS =========================================================
def move_cell(self, x1, y1, x2, y2):
if not ((x1,y1) in self.grid and (x2,y2) in self.grid):
self.error('Invalid coordinates')
return
self.add_undo('mi', ((x1, y1, self.grid[x1,y1]), (x2, y2, self.grid[x2,y2])))
self.grid[x2,y2] = self.grid[x1,y1]
self.grid[x1,y1] = None
self.draw_scene()
def edit_cell(self, x, y, text):
if (x,y) not in self.grid:
self.error('Invalid coordinate')
return
if not text:
self.prompt('e{} {} {}'.format(x, y, self.grid[x,y][0]))
return
self.add_undo('e', (x, y, self.grid[x,y]))
self.set_cell(x, y, text)
self.draw_scene()
def clear_cell(self, x, y):
if (x,y) not in self.grid:
self.error('Invalid coordinate')
return
self.add_undo('e', (x, y, self.grid[x,y]))
self.grid[x,y] = None
self.draw_scene()
def set_cell(self, x, y, name):
if x == 0 and y == 0:
self.error('Can\'t edit cell 0,0!')
return
if x == 0 or y == 0:
fd = 'bold'
else:
fd = 'def'
name = name.replace('\\n','\n')
size = self.font_data[fd][1].boundingRect(0,0,150,10000,Qt.TextWordWrap,name).size()
self.grid[x,y] = (name, (size.width(), size.height()))
# ======== UNDO ==========================================================
def add_undo(self, cmd, arg):
self.modified_flag = True
self.update_title()
self.undo_stack.append((cmd, arg))
def undo(self):
if not self.undo_stack:
self.error('Nothing to undo')
return
cmd, arg = self.undo_stack.pop()
if cmd == 'e':
x, y, item = arg