本文整理汇总了Python中vector.Vector.append方法的典型用法代码示例。如果您正苦于以下问题:Python Vector.append方法的具体用法?Python Vector.append怎么用?Python Vector.append使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vector.Vector
的用法示例。
在下文中一共展示了Vector.append方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_delete_many
# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import append [as 别名]
def test_delete_many():
v = Vector()
for x in range(1000):
v.append(x)
c = v.capacity
for x in range(1000):
v.delete(v.length // 2)
assert v.capacity < c
assert v.length == 0
示例2: test_delete
# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import append [as 别名]
def test_delete():
v = Vector()
v.append(1)
v.append(2)
v.append(3)
assert v.length == 3
v.delete(1)
assert v.length == 2
assert v[0] == 1
assert v[1] == 3
示例3: test_set_item
# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import append [as 别名]
def test_set_item():
v = Vector()
for x in range(100):
v.append(x)
v[0] = 991
v[20] = 992
v[40] = 993
v[99] = 994
assert v[0] == 991
assert v[20] == 992
assert v[40] == 993
assert v[99] == 994
示例4: __mul__
# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import append [as 别名]
def __mul__(self, other):
if isinstance(other, Number):
return np.multiply(self, other)
elif isinstance(other, np.matrix) and other.shape[0] == 4:
return np.matrix.__mul__(self, other)
elif isinstance(other, (np.ndarray, list, tuple)):
if isinstance(other, (list, tuple)):
other = Vector(other)
should_extend = len(other) == 3
if should_extend:
other = list(other)
other.append(1)
other = Vector(other)
result = Vector(np.matrix.__mul__(self, other.flat).flat)
if should_extend:
result[0:3] /= result[3]
return result[0:3]
else:
return result
return Vector(np.matrix.__mul__(self, other).flat)
示例5: test_append
# 需要导入模块: from vector import Vector [as 别名]
# 或者: from vector.Vector import append [as 别名]
def test_append():
v = Vector()
for x in range(1000):
v.append(x)
assert v[x] == x
assert v.length == 1000