本文整理汇总了Python中vector.Vector.dot_product方法的典型用法代码示例。如果您正苦于以下问题:Python Vector.dot_product方法的具体用法?Python Vector.dot_product怎么用?Python Vector.dot_product使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vector.Vector
的用法示例。
在下文中一共展示了Vector.dot_product方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_dot_product_and_angle
# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import dot_product [as 别名]
def test_dot_product_and_angle():
"""Quiz 3 calculating the dot product and angle of two Vectors"""
vector1 = Vector([7.887, 4.138])
vector2 = Vector([-8.802, 6.776])
answer1 = Decimal('-41.382')
assert round(vector1.dot_product(vector2), 3) == answer1
vector3 = Vector([-5.955, -4.904, -1.874])
vector4 = Vector([-4.496, -8.755, 7.103])
answer2 = Decimal('56.397')
assert round(vector3.dot_product(vector4), 3) == answer2
vector5 = Vector([3.183, -7.627])
vector6 = Vector([-2.668, 5.319])
answer3 = 3.072
assert round(vector5.angle_radians(vector6), 3) == answer3
vector7 = Vector([7.35, 0.221, 5.188])
vector8 = Vector([2.751, 8.259, 3.985])
answer4 = 60.276
assert round(vector7.angle_degrees(vector8), 3) == answer4
示例2: calculate_QR
# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import dot_product [as 别名]
def calculate_QR(mat):
q_list = []
R = Matrix(mat.size())
for i in range(mat.size()):
vector = Vector(mat.get_col(i))
aux_vec = Vector([0] * mat.size())
for j in range(i):
prod = vector.dot_product(q_list[j])
R.set(j,i, prod)
aux_vec += q_list[j] * prod
e = vector - aux_vec
R.set(i,i,e.get_norm())
q_list.append(e.normalize())
return Matrix.from_col_lists([x.get_values() for x in q_list]), R
示例3: format
# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import dot_product [as 别名]
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])
print v.normalized()
# Dot Product
print ''
print 'Dot Product'
v1 = Vector([7.887, 4.138])
v2 = Vector([-8.802, 6.776])
print v1.dot_product(v2)
v1 = Vector([-5.955, -4.904, -1.874])
v2 = Vector([-4.496, -8.755, 7.103])
print v1.dot_product(v2)
# Angles
v1 = Vector([3.183, -7.627])
v2 = Vector([-2.668, 5.319])
print ''
print 'Angle Radians'
print v1.angle_radians(v2)
print v1.angle_with(v2, False)
v1 = Vector([7.35, 0.221, 5.188])
v2 = Vector([2.751, 8.259, 3.985])
print ''
print 'Angle Degrees'