本文整理汇总了Python中vector.Vector.random方法的典型用法代码示例。如果您正苦于以下问题:Python Vector.random方法的具体用法?Python Vector.random怎么用?Python Vector.random使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vector.Vector
的用法示例。
在下文中一共展示了Vector.random方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_random_position
# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import random [as 别名]
def _get_random_position(cls):
"""
Returns random, not busy position
"""
while True:
size = PLAYFIELD_SIZE / 2
pos = Vector.random(-size, size)
if not cls.is_interliaced(pos):
break
return pos
示例2: print_cute_table
# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import random [as 别名]
def print_cute_table():
"""
Create a table of errors of two methods
(but we know, which method is bad...)
Table based on random values.
"""
pattern = "{size}\t\t{linsolve}\t\t{unstable}"
print("\t\tTable of errors\n" + '=' * 50 )
print("size of system\terror of linsolve\t\t" +
"error of unstable linsolve (they are just wonderful!)")
for size in range(20, 401, 20):
m = TridiagonalMatrix.random(size)
m.a = m.a + m.c + m.b
x = Vector.random(size)
d = m * x
err = abs(m.linsolve(d) - x)
err_unstable = abs(m.unstable_linsolve(d) - x)
print(pattern.format(size=size, linsolve=err, unstable=err_unstable))
示例3: test_random
# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import random [as 别名]
def test_random():
length = 5
assert Vector.random(length, 0, 10, Zeroes()) == Vector.zeroes(length)
assert Vector.random(length, 0, 10, Ones()) == Vector([1] * length)
assert Vector.random(length, 0, 10, Count()) == Vector([1, 2, 3, 4, 5])
示例4: random
# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import random [as 别名]
def random(size):
"""
Return random tridiagonal matrix of given size
"""
return TridiagonalMatrix(*[Vector.random(size) for _ in range(3)])