📘
Mathematical Functions
Problem Statement
Apply mathematical functions to NumPy arrays.
Background
NumPy provides universal functions (ufuncs):
- np.sqrt(): Square root
- np.exp(): Exponential (e^x)
- np.log(): Natural logarithm
- np.abs(): Absolute value
Your Task
Write a function math_functions(arr) that returns a dictionary with:
- "sqrt": Square root of each element (rounded to 2 decimals)
- "square": Square of each element
- "abs": Absolute value of each element
Output Format
Return a dictionary with exactly these three keys. All values as lists.
Example:
Input:
[1, 4, 9, 16]
Output:
{'sqrt': [1.0, 2.0, 3.0, 4.0], 'square': [1, 16, 81, 256], 'abs': [1, 4, 9, 16]}Reasoning:
sqrt: [1, 2, 3, 4], square: [1, 16, 81, 256]
Constraints:
- Input will contain non-negative numbers
- Round sqrt results to 2 decimal places
Editor
Python 3.13.1
Test Results
0/0Run code to see test results.