Matrices in Python
Doing matrix operations by hand is tedious and error-prone, but you don’t have to do everything by hand. This section describes a nice alternative:
- If you haven’t already done so, follow steps 1 to 3 at the beginning of this chapter’s Jupyter notebooks section.
- In the upper-left corner of the page, click the New File button.
- In the resulting Launcher tab, click the Notebook | Qiskit button.
A new, empty Jupyter/Python notebook appears.
- In the empty cell, near the top of the notebook, type the following code, and then press Shift+Enter:
import numpy as np
No output shows up on the screen, but behind the scenes, this statement makes a library named NumPy
available to the code in your notebook. As the name suggests, NumPy
deals with numbers and other mathematical concepts. From this point on, your code uses np
as a nickname for NumPy
.
Important note
The previous section (Copying this book’s code...