本文整理汇总了Python中vector.Vector.times_scalar方法的典型用法代码示例。如果您正苦于以下问题:Python Vector.times_scalar方法的具体用法?Python Vector.times_scalar怎么用?Python Vector.times_scalar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vector.Vector
的用法示例。
在下文中一共展示了Vector.times_scalar方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_scalar_multiplication_by_scalar
# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import times_scalar [as 别名]
def test_scalar_multiplication_by_scalar(self):
v = Vector([1.671, -1.012, -0.318])
self.assertVecEqual(
['12.3821100000000005402078784300', '-7.49892000000000022279067479758', '-2.35638000000000008138822948922'],
v.times_scalar(7.41))
示例2: Vector
# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import times_scalar [as 别名]
print 'Addition'
print v1.plus(v2)
# Subtraction
v1 = Vector([7.119, 8.215])
v2 = Vector([-8.223, 0.878])
print ''
print 'Subtraction'
print v1.minus(v2)
# Scalar Multiplication
s = 7.41
v = Vector([1.671, -1.012, -0.318])
print ''
print 'Scalar Multiplication'
print v.times_scalar(s)
# Magnitude
print ''
print 'Magnitude'
v = Vector([-0.221, 7.437])
print format(v.magnitude(), '.5f')
v = Vector([8.813, -1.331, -6.247])
print format(v.magnitude(), '.5f')
# Normalize
print ''
print 'Normalize'
v = Vector([5.581, -2.136])
print v.normalized()
v = Vector([1.996, 3.108, -4.554])