Part 4A : Lists, Arrays and Matrices in Python 3

Arrays

An array is a data structure, with elements of similar data types and an index associated with every element.

Index is used to locate the element (associated with it) in memory. In Python, index starts from 0 (so first element will have index = 0, second element has index = 1 and so on).

Lists

List is a variation of array that supports different data types inside a single structure. List also has indexes associated with every element.

Both array and list are mutable data structures i.e. their elements can be altered after they are defined.

Matrices in Python

A matrix can be represented in Python by creating an array within an array, as shown in example below.

Numpy

Numpy is a Python library that helps us to create faster arrays and perform linear algebra.

Advantages of using Numpy over :

  1. Takes less space
  2. Faster than normal python array
  3. Has predefined functions for linear algebra (numpy.linalg)

Installing numpy :

python3 -m pip install numpy

Creating a numpy array :

Scalar multiplication has been covered up in a previous article.

Examples are available as a GitHub gist and a jupyter notebook.

Sources to learn Python :

Free Courses :

w3schools

codecademy

Video tutorial :

sentdex

Book :

Think Python: How to Think Like a Computer Scientist 2nd Edition by Allen B. Downey