OKPEDIA PYTHON VECTOR

How to make vector in Python

To create a vector in Python we use the array function of the numpy library.

array(x)

The argument x is a list containing the elements [e1,e2,...,en] of the vector.

This function allows vector calculations in Python.

an example of multidimensional vector

Example

We import the numpy module into the python interpreter.

import numpy as np

We assign a vector to a variable with the function array().

v=np.array([1,2,3,4,5])

It is a vector composed of five elements:

an example of a vector

The content of the variable v is

array([1, 2, 3, 4, 5])

Now the variable v can be used to perform all operations on vectors and matrices of linear algebra. For example, the addition between vectors (v + v), the multiplication between vectors (v * v), in the product for a scalar (k * v), in the scalar product, etc.

https://how.okpedia.org/en/python/how-to-make-a-vector-in-python


Report an error or share a suggestion to enhance this page


Python


FacebookTwitterLinkedinLinkedin