June 2020
Intermediate to advanced
382 pages
11h 39m
English
A vector is a single dimension structure to store data. They are one of the most popular data structures in Python. There are two ways of creating vectors in Python as follows:
Using a Python list: The simplest way of creating a vector is by using a Python list, as follows:
>>> myVector = [22,33,44,55]>>> print(myVector) [22 33 44 55]>>> print(type(myVector))<class 'list'>
Note that this code will create a list with four elements.
Using a numpy array: Another popular way of creating a vector is by using NumPy arrays, as follows:
>>> myVector = np.array([22,33,44,55]) >>> print(myVector) [22 33 44 55]>>> print(type(myVector))<class 'numpy.ndarray'>
Note that we created myVector using np.array in this code.