sum_vectors

compas.geometry.sum_vectors(vectors, axis=0)[source]

Calculate the sum of a series of vectors along the specified axis.

Parameters
  • vectors (sequence[[float, float, float] | compas.geometry.Vector]) – A list of vectors.

  • axis (int, optional) – If axis == 0, the sum is taken per column. If axis == 1, the sum is taken per row.

Returns

list[float] – The length of the list is len(vectors[0]), if axis == 0. The length is len(vectors), otherwise.

Examples

>>> vectors = [[1.0, 2.0, 3.0], [1.0, 2.0, 3.0], [1.0, 2.0, 3.0]]
>>> sum_vectors(vectors)
[3.0, 6.0, 9.0]
>>> sum_vectors(vectors, axis=1)
[6.0, 6.0, 6.0]