Addition with Vectors

vector_sum(vector_one, vector_two)

Calculates the sum of two vectors

Parameters
  • vector_one (list of int or float) – List of numbers representing a vector

  • vector_two (list of int or float) – List of numbers representing a vector

Raises
  • TypeError – Arguments must be 1-dimensional lists

  • TypeError – Elements of arguments must be integers or floats

  • ValueError – Both arguments must contain the same number of elements

Returns

vector – List in which each element is the sum of the corresponding elements from the input vectors

Return type

list of int or float

Notes

  • First vector: \(\mathbf{a} = \langle a_1, a_2, \cdots, a_n \rangle\)

  • Second vector: \(\mathbf{b} = \langle b_1, b_2, \cdots, b_n \rangle\)

  • Sum of vectors: \(\mathbf{a} + \mathbf{b} = \langle a_1 + b_1, a_2 + b_2, \cdots, a_n + b_n \rangle\)

  • Vector Addition

Examples

Import vector_sum function from regressions library
>>> from regressions.vectors.addition import vector_sum
Add [1, 2, 3] and [4, 5, 6]
>>> vector_3d = vector_sum([1, 2, 3], [4, 5, 6])
>>> print(vector_3d)
[5, 7, 9]
Add [-5, 12] and [3, -7]
>>> vector_2d = vector_sum([-5, 12], [3, -7])
>>> print(vector_2d)
[-2, 5]