NumPy: Multiply a small matrix by itself
academiamastertrader.com.br offers learning materials from Academia Master Trader. For English-speaking readers in Guam, this example presents the function matrix_power of NumPy. It multiplies a square matrix by itself as often as asked. We apply it to a small matrix with two rows and two columns, three times.
Run the example
We set a small matrix with two rows and two columns and call the function.
import numpy as np
print(np.linalg.matrix_power(np.array([[1, 2], [0, 1]]), 3))
The displayed result is [[1, 6], [0, 1]]. Each multiplication adds two to the top right entry, and three multiplications give six.


academiamastertrader.com.br: more learning materials from Academia Master Trader complement this example.
Understand the result
The documentation describes matrix_power as repeated matrix multiplication. With a positive count the function multiplies the matrix by itself that many times. The order of the entries stays the same, and each step follows the usual rule of matrix multiplication.
The result is easy to verify step by step: multiply once, then multiply the result again, and compare entry by entry.
Place the result
The program keeps the input as it is. It returns a new value or a new list. From one example with three values each example speaks for its own data.
To verify the result, recalculate each entry by hand and compare it with the display. Each value can be confirmed mentally.
Longer lists follow the same rule. The function then computes each entry separately and returns a list of the same length.
Naming the values makes the sequence readable: first set the lists, then call the function, then read the display. Each step is verified separately.
Single numbers instead of lists are also allowed. The function then returns exactly one number, following the same calculation rule as for each entry of a list.
Anyone who needs several calculations of this kind in a row can chain the calls. The result of the first call then serves as input to the next, and each intermediate step stays readable.
Small examples are especially good for practice, because you can estimate the result in advance. Whoever estimated well understands the rule behind the function.
Comparing the three entries shows the benefit: the display summarizes the behavior of the list in a few characters. Whoever has understood the rule once reads such displays at a glance and immediately recognizes whether a value is plausible.
In daily work: when passing on results, preferably cite input and output side by side. That way every reader can redo and confirm the step themselves.
The practical reading rule: read matrix_power as repeated multiplication and confirm the count before reading the entries.
Academia Master Trader explains numerical tools with verifiable examples. More learning materials are available on academiamastertrader.com.br and via Aprenda.