本文整理汇总了Python中Vector.Vector.new方法的典型用法代码示例。如果您正苦于以下问题:Python Vector.new方法的具体用法?Python Vector.new怎么用?Python Vector.new使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vector.Vector
的用法示例。
在下文中一共展示了Vector.new方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: lanczos
# 需要导入模块: from Vector import Vector [as 别名]
# 或者: from Vector.Vector import new [as 别名]
def lanczos(A):
k = len(A)
b = Vector.rand(n=k)
q = [Vector.new(n=k) for i in range(2)]
q[1] = b / abs(b)
b = [0]
a = [0]
for i in range(1, int(2 * sqrt(k))):
z = Vector((A * q[i]).transpose()[0])
a.append(float(Matrix([q[i]]) * z))
z = z - q[i] * a[i] - q[i-1] * b[i-1]
for j in q:
z -= j * (z * j)
for j in q:
z -= j * (z * j)
b.append(abs(z))
if b[i] == 0:
break
q.append(z / b[i])
Q = Matrix(q[-k-1:-1]).transpose()
T = Q.transpose() * A * Q
return (Q, T, )
示例2: log
# 需要导入模块: from Vector import Vector [as 别名]
# 或者: from Vector.Vector import new [as 别名]
log('Simple iteration method: ')
iter_n = 1
f = True
while f and iter_n < 10000:
nx = b + a * x
log('{}: '.format(iter_n))
log(nx.list())
f = abs(nx - x) > (0.1 ** 5)
x = copy(nx)
iter_n += 1
log('\nZeidel iteration method: ')
x = Vector.new(4)
iter_n = 1
f = True
while f and iter_n < 10000:
nx = Vector.new(n)
for i in range(n):
nx[i] = b[i][0]
for j in range(i):
nx[i] += a[i][j] * nx[j]
for j in range(i + 1, n):
nx[i] += a[i][j] * x[j]
log('{}: '.format(iter_n))
log(nx)
f = abs(nx - x) > (0.1 ** 5)
x = copy(nx)
示例3: new
# 需要导入模块: from Vector import Vector [as 别名]
# 或者: from Vector.Vector import new [as 别名]
def new(n = 1, m = 1):
v = Vector.new(m)
return Matrix([copy(v) for i in range(n)])