Compute element-wise power of two NumPy arrays if their shapes match. Parameters ---------- x : np.ndarray Base array. y : np.ndarray Exponent array. Returns ------- None Prints the element-wise powers using both operator ** and np.power.
(x: np.ndarray, y: np.ndarray)
| 17 | |
| 18 | |
| 19 | def get_array(x: np.ndarray, y: np.ndarray) -> None: |
| 20 | """ |
| 21 | Compute element-wise power of two NumPy arrays if their shapes match. |
| 22 | |
| 23 | Parameters |
| 24 | ---------- |
| 25 | x : np.ndarray |
| 26 | Base array. |
| 27 | y : np.ndarray |
| 28 | Exponent array. |
| 29 | |
| 30 | Returns |
| 31 | ------- |
| 32 | None |
| 33 | Prints the element-wise powers using both operator ** and np.power. |
| 34 | |
| 35 | Example: |
| 36 | >>> import numpy as np |
| 37 | >>> a = np.array([[1, 2], [3, 4]]) |
| 38 | >>> b = np.array([[2, 2], [2, 2]]) |
| 39 | >>> get_array(a, b) # doctest: +ELLIPSIS |
| 40 | Array of powers without using np.power: [[ 1 4] |
| 41 | [ 9 16]] |
| 42 | Array of powers using np.power: [[ 1 4] |
| 43 | [ 9 16]] |
| 44 | """ |
| 45 | if x.shape == y.shape: |
| 46 | np_pow_array = x**y |
| 47 | print("Array of powers without using np.power: ", np_pow_array) |
| 48 | print("Array of powers using np.power: ", np.power(x, y)) |
| 49 | else: |
| 50 | print("Error: Shape of the given arrays is not equal.") |
| 51 | |
| 52 | |
| 53 | if __name__ == "__main__": |
no test coverage detected