Skip to content

Commit 1909143

Browse files
committed
Done with the required changes
1 parent 955c792 commit 1909143

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

maths/fibonacci.py

+21
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,27 @@ def matrix_pow_np(m: ndarray, power: int) -> ndarray:
247247
248248
Returns:
249249
The matrix raised to the power.
250+
251+
Raises:
252+
ValueError: If power is negative.
253+
254+
>>> m = np.array([[1, 1], [1, 0]], dtype=int)
255+
>>> matrix_pow_np(m, 0) # Identity matrix when raised to the power of 0
256+
array([[1, 0],
257+
[0, 1]])
258+
259+
>>> matrix_pow_np(m, 1) # Same matrix when raised to the power of 1
260+
array([[1, 1],
261+
[1, 0]])
262+
263+
>>> matrix_pow_np(m, 5)
264+
array([[8, 5],
265+
[5, 3]])
266+
267+
>>> matrix_pow_np(m, -1)
268+
Traceback (most recent call last):
269+
...
270+
ValueError: power is negative
250271
"""
251272
result = np.array([[1, 0], [0, 1]], dtype=int) # Identity matrix
252273
base = m

0 commit comments

Comments
 (0)