本文整理汇总了Python中pycast.common.matrix.Matrix.__str__方法的典型用法代码示例。如果您正苦于以下问题:Python Matrix.__str__方法的具体用法?Python Matrix.__str__怎么用?Python Matrix.__str__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pycast.common.matrix.Matrix
的用法示例。
在下文中一共展示了Matrix.__str__方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: matrix_string_representation_with_precision_test
# 需要导入模块: from pycast.common.matrix import Matrix [as 别名]
# 或者: from pycast.common.matrix.Matrix import __str__ [as 别名]
def matrix_string_representation_with_precision_test(self):
"""Test if the precision is set correctly and used when printing a Matrix.
"""
size = 2
data = [
[1.0123343, -2.012341234123],
[3.04674567566, 4.012341234120]
]
mtrx = Matrix(size, size)
mtrx.initialize(data, rowBased=True)
mtrx.set_string_precision(4)
rep = mtrx.__str__()
# should print the number with 4 digits after decimal point
self.assertTrue(rep.find(" 3.0467 ") >= 0)
self.assertTrue(rep.find(" -2.0123") >= 0)
# but should not print the full number
self.assertFalse(rep.find(" 3.04674567566") >= 0)
self.assertFalse(rep.find(" -2.012341234123 ") >= 0)
# change precision
mtrx.set_string_precision(2)
rep = mtrx.__str__()
print mtrx
# should print the number with 2 digits after decimal point
# numbers should be rounded
self.assertTrue(rep.find(" 3.05 ") >= 0)
self.assertTrue(rep.find(" -2.01") >= 0)
示例2: matrix_string_representation_test
# 需要导入模块: from pycast.common.matrix import Matrix [as 别名]
# 或者: from pycast.common.matrix.Matrix import __str__ [as 别名]
def matrix_string_representation_test(self):
"""Test the String representation of a Matrix instance."""
matrix = Matrix(2, 2)
a = [[1, 2], [-3, 4]]
matrix.initialize(a, rowBased=True)
rep = matrix.__str__()
self.assertTrue(rep.find(" 1.0") >= 0)
self.assertTrue(rep.find(" -3.0") >= 0)
# only one space before a negative number
self.assertFalse(rep.find(" -3.0") >= 0)
self.assertTrue(rep.find("Matrix") >= 0)