本文整理汇总了Python中vector.Vector.scalarMultiple方法的典型用法代码示例。如果您正苦于以下问题:Python Vector.scalarMultiple方法的具体用法?Python Vector.scalarMultiple怎么用?Python Vector.scalarMultiple使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vector.Vector
的用法示例。
在下文中一共展示了Vector.scalarMultiple方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: calculateLocation
# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import scalarMultiple [as 别名]
def calculateLocation(self, robot_classification, bucket):
''' If the location can be taken from the bucket, return the mean '''
if bucket is not None and len(bucket) > 1:
points = [x for (x, _) in bucket]
return meanPoint(points)
if not self.previous_locations[robot_classification].full():
return None
''' Get the ArrayQueue(previous locations) for robot with the 'key' identifier '''
points_queue = self.previous_locations[robot_classification]
trajectory_vector = linear_regression(points_queue)
if trajectory_vector is None:
return None
trajectory_vector.rescale(1)
speed = self.getSpeed(robot_classification)
dislocation = Vector.scalarMultiple(trajectory_vector, speed)
prev_location = points_queue.getLeft()
estimated_robot_position = Vector.addToPoint( prev_location, dislocation )
if self.outOfBounds(estimated_robot_position):
return None
return estimated_robot_position
示例2: linear_regression
# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import scalarMultiple [as 别名]
def linear_regression(points_queue):
points = points_queue.iteritems()
#print "Points -----> ", points
if None in points:
return None # Might need revisiting
points = list(set(points))
if distance(points[0], meanPoint(points)) < 200:
return Vector(0, 0)
num_pts = len(points)
print num_pts
# M = np.array([points[0]])
# for i in range(1, num_pts):
# print points[i]
# M = np.append(M, [points[i]], axis=0)
# print M
descartes_points = [ transformCoordstoDecartes(x) for x in points ]
M = np.array( [[a, b] for (a, b) in descartes_points] )
print "M ---------->", M
xc = M[:, [0]]
print "Xc --------->", xc
yc = M[:, [1]]
print "Yc --------->", yc
ones = np.ones((num_pts, 1))
X = np.concatenate((ones, xc), axis=1)
X_intermediary = np.dot(X.T, X)
Y_intermediary = np.dot(X.T, yc)
R = np.dot(inv(X_intermediary), Y_intermediary)
k = R[1][0]
beginning_x = points_queue.getRight()[0]
end_x = points_queue.getLeft()[0]
final_vector = Vector(1, k)
''' If the direction of the robot is negative in the x-axis, flip the vector over y = x '''
if beginning_x > end_x:
final_vector = Vector.scalarMultiple(final_vector, -1)
# if beginning_x < end_x:
# final_vector = Vector(1, k)
# else:
# final_vector = Vector(-1, -k)
final_vector.switchCoords()
return final_vector