当前位置: 首页>>代码示例>>Python>>正文


Python Vector.scalarMultiple方法代码示例

本文整理汇总了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
开发者ID:pbsinclair42,项目名称:SDP-2016,代码行数:29,代码来源:tracker.py

示例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
开发者ID:pbsinclair42,项目名称:SDP-2016,代码行数:56,代码来源:algebra.py


注:本文中的vector.Vector.scalarMultiple方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。