Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions 05_docstring/submissions/ball133.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import numpy as np


def afunc(array1: np.ndarray, array2: np.ndarray, mode: str = "+", pow: int = 2) -> np.ndarray:
"""Sums two matrices, then exponentiates each element by pow power.

Args:
array1: A numpy.ndarray.
array2: A numpy.ndarray.
mode: A string representing '+' or '-' matrix operations.
pow: An integer representing the power.

Returns:
A numpy.ndarray matrix, summing the passed matrices and exponentiating each element by pow.
"""
assert array1.shape == array2.shape, "size mismatch"
assert type(pow) == int, "pow should be type int"

if mode == "+":
result = array1 + array2
elif mode == "-":
result = array1 - array2
else:
raise ValueError(f"mode is either '+' or '-' but got {mode}")

result = result**pow
return result