Multiplication with Vectors

scalar_product_vector(vector, scalar)

Calculates the product of a vector and a scalar

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

  • scalar (int or float) – Number representing a scalar

Raises
  • TypeError – First argument must be a 1-dimensional list

  • TypeError – Elements of first argument must be integers or floats

  • TypeError – Second argument must be an integer or a float

Returns

product – List of numbers in which each element is the product of the scalar factor and the corresponding element from the input vector

Return type

list of int or float

Notes

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

  • Scalar: \(c\)

  • Scalar product: \(c\cdot{\mathbf{a}} = \langle c\cdot{a_1}, c\cdot{a_2}, \cdots, c\cdot{a_n} \rangle\)

  • Scalar Multiplication

Examples

Import scalar_product_vector function from regressions library
>>> from regressions.vectors.multiplication import scalar_product_vector
Multiply [1, 2, 3] and -2
>>> product_3d = scalar_product_vector([1, 2, 3], -2)
>>> print(product_3d)
[-2, -4, -6]
Multiply [-5, 12] and 3
>>> product_2d = scalar_product_vector([-5, 12], 3)
>>> print(product_2d)
[-15, 36]
dot_product(vector_one, vector_two)

Calculates the product 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

product – Number created by summing the products of the corresponding terms from each input vector

Return type

float

See also

matrix_product()

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\):

  • Dot product of vectors: \(\mathbf{a}\cdot{\mathbf{b}} = a_1\cdot{b_1} + a_2\cdot{b_2} + \cdots + a_n\cdot{b_n}\)

  • Dot Product

Examples

Import dot_product function from regressions library
>>> from regressions.vectors.multiplication import dot_product
Multiply [1, 2, 3] and [4, 5, 6]
>>> product_3d = dot_product([1, 2, 3], [4, 5, 6])
>>> print(product_3d)
32.0
Multiply [-5, 12] and [3, -7]
>>> product_2d = dot_product([-5, 12], [3, -7])
>>> print(product_2d)
-99.0