2-dimensional arrays can be seen as matrices. This is a convenient way of storing and manipulating multivariate data with python.
An array is a grid of numeric data of the same type. Arrays come in different ranks, shapes and sizes.
Rank |
The number of dimensions in an array |
Shape |
The number of elements in each dimension of an array and is represented as a tuple |
Size |
The total number of elements in an array |
Rank 1 array
This 1-dimensional array has 8 elements. Thus, its shape is the tuple (8,) and its size is 8.
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
Rank 2 array
This 2-dimensional array, or a matrix, has 3 rows and 5 columns. Thus, its shape is the tuple (3,5) and its size is 15.
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
We can create NumPy arrays from nested Python lists, and access the elements in the arrays using square brackets.
If you are curious about how data is arranged in NumPy and using reshape, check out this resource.
To get started we will first have to import the library:
Syntax
import numpy as np
You are expected to comply with University policies and guidelines namely, Appropriate Use of Information Resources Policy, IT Usage Policy and Social Media Policy.
Users will be personally liable for any infringement of Copyright and Licensing laws.
Unless otherwise stated, all guide content is licensed by CC BY-NC 4.0.