本文整理汇总了Python中vector.Vector方法的典型用法代码示例。如果您正苦于以下问题:Python vector.Vector方法的具体用法?Python vector.Vector怎么用?Python vector.Vector使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vector
的用法示例。
在下文中一共展示了vector.Vector方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import vector [as 别名]
# 或者: from vector import Vector [as 别名]
def __init__(self, pixels, width, height):
self.pixels = pixels
self.width = width
self.height = height
self.canvas = Canvas(width, height, pixels)
# setup key handlers
key_esc = 27
self.handlers = {
key_esc: self.exit
}
self.v1 = Vertex(Vector(0, 0), Color.cyan())
self.v2 = Vertex(Vector(300, 100), Color.red())
self.v3 = Vertex(Vector(200, 300), Color.green())
示例2: draw_line
# 需要导入模块: import vector [as 别名]
# 或者: from vector import Vector [as 别名]
def draw_line(self, p1, p2):
"""
:type p1: Vector
:type p2: Vector
"""
# x1, y1, x2, y2 = map(int, [p1.x, p1.y, p2.x, p2.y])
x1, y1, x2, y2 = [int(i) for i in [p1.x, p1.y, p2.x, p2.y]]
dx = x2 - x1
dy = y2 - y1
if abs(dx) > abs(dy):
xmin, xmax = sorted([x1, x2])
ratio = 0 if dx == 0 else dy / dx
for x in range(xmin, xmax):
y = y1 + (x - x1) * ratio
self.draw_point(Vector(x, y))
else:
ymin, ymax = sorted([y1, y2])
ratio = 0 if dy == 0 else dx / dy
for y in range(ymin, ymax):
x = x1 + (y - y1) * ratio
self.draw_point(Vector(x, y))
示例3: K_Means
# 需要导入模块: import vector [as 别名]
# 或者: from vector import Vector [as 别名]
def K_Means(list_of_points, no_centroids):
centroids = []
for i in range(no_centroids):
centroids.append(Vector())
for centroid in centroids:
random_point = list_of_points[randint(0, (len(list_of_points)-1) )]
centroid.features = copy.deepcopy(random_point.features)
clusters = cluster_assignment(list_of_points, centroids)
for i in range(0, 300): # iterate until convergence, default 300
centroids = move_centroid(clusters)
clusters = cluster_assignment(list_of_points, centroids)
distortion_sum = 0.0
for key in clusters:
for point in clusters[key]:
distortion_sum += point.euclidean_dist(centroids[key])
distortion = distortion_sum / float(len(list_of_points))
return [distortion, clusters]
示例4: computeScores2
# 需要导入模块: import vector [as 别名]
# 或者: from vector import Vector [as 别名]
def computeScores2(inputFile, outCSV):
with open(outCSV, "wb") as outF:
a = csv.writer(outF, delimiter=',')
a.writerow(["x-coordinate", "y-coordinate", "Similarity_score"])
file1_parsedData = parser.from_file(inputFile)
row_list = ast.literal_eval(file1_parsedData["content"])
rows_tuple = itertools.combinations(row_list, 2)
for row1, row2 in rows_tuple:
try:
row_cosine_distance = [row_list.index(row1), row_list.index(row2)]
v1 = Vector(inputFile, row1)
v2 = Vector(inputFile, row2)
row_cosine_distance.append(v1.cosTheta(v2))
a.writerow(row_cosine_distance)
except ConnectionError:
sleep(1)
except KeyError:
continue
示例5: _draw_boundary
# 需要导入模块: import vector [as 别名]
# 或者: from vector import Vector [as 别名]
def _draw_boundary(self):
bd = self.boundary
if not bd:
return
o = Vector(*[bd[i][0] for i in range(3)])
dx = bd[0][1] - bd[0][0]
dy = bd[1][1] - bd[1][0]
dz = bd[2][1] - bd[2][0]
dxv = Vector(dx, 0, 0)
dyv = Vector(0, dy, 0)
dzv = Vector(0, 0, dz)
glBegin(GL_LINES)
self._draw_lines(o, o + dxv, dyv, (0.7, 0, 0))
self._draw_lines(o, o + dyv, dxv, (0.7, 0, 0))
self._draw_lines(o, o + dxv, dzv, (0, 0.7, 0))
self._draw_lines(o, o + dzv, dxv, (0, 0.7, 0))
self._draw_lines(o, o + dyv, dzv, (0, 0, 0.7))
self._draw_lines(o, o + dzv, dyv, (0, 0, 0.7))
glEnd()
示例6: test_vector_unary_minus
# 需要导入模块: import vector [as 别名]
# 或者: from vector import Vector [as 别名]
def test_vector_unary_minus():
assert -Vector([1, 2, 3]) == Vector([-1, -2, -3])
示例7: test_vector_unary_minus
# 需要导入模块: import vector [as 别名]
# 或者: from vector import Vector [as 别名]
def test_vector_unary_minus(self):
self.assertEqual(-Vector([1, 2, 3]), Vector([-1, -2, -3]))
示例8: v2d
# 需要导入模块: import vector [as 别名]
# 或者: from vector import Vector [as 别名]
def v2d():
return Vector([1, 2])
示例9: test_2d_vector_addition
# 需要导入模块: import vector [as 别名]
# 或者: from vector import Vector [as 别名]
def test_2d_vector_addition(v2d):
v = Vector([3, 4])
assert v + v2d == Vector([4, 6])
示例10: test_mismatched_lengths_exception
# 需要导入模块: import vector [as 别名]
# 或者: from vector import Vector [as 别名]
def test_mismatched_lengths_exception(v2d):
v = Vector([1, 2, 3])
with pytest.raises(ValueError):
v + v2d
示例11: setUp
# 需要导入模块: import vector [as 别名]
# 或者: from vector import Vector [as 别名]
def setUp(self):
self.v2d = Vector([1, 2])
示例12: test_2d_vector_addition
# 需要导入模块: import vector [as 别名]
# 或者: from vector import Vector [as 别名]
def test_2d_vector_addition(self):
v = Vector([3, 4]) + self.v2d
self.assertEqual(v, Vector([4, 6]))
示例13: test_mismatched_lengths_exception
# 需要导入模块: import vector [as 别名]
# 或者: from vector import Vector [as 别名]
def test_mismatched_lengths_exception(self):
v = Vector([1, 2, 3])
with self.assertRaises(ValueError):
v + self.v2d
示例14: test_reversed_operator
# 需要导入模块: import vector [as 别名]
# 或者: from vector import Vector [as 别名]
def test_reversed_operator(self):
v = [10, 20] + self.v2d
self.assertEqual(v, Vector([11, 22]))
示例15: draw_point
# 需要导入模块: import vector [as 别名]
# 或者: from vector import Vector [as 别名]
def draw_point(self, point, color=Color.cyan()):
"""
:type point: Vector
:type color: Color
:return: None
"""
if 0 <= point.x < self.width and 0 <= point.y < self.height:
self.put_pixel(point.x, point.y, color)