Input:arr is a 1-D array of four non-negative integers, [1,4,9,16]. Each of the three results is computed element by element, so every output list also has 4 entries in the same order.
sqrt: each value is a perfect square, so 1=1, 4=2, 9=3, 16=4. A square root comes back as a real number, which is why the list reads [1.0, 2.0, 3.0, 4.0] with decimals. Rounding to 2 places only matters for non-perfect squares, e.g. 2≈1.4142→1.41.
square:12=1, 42=16, 92=81, 162=256, giving [1, 16, 81, 256]. Squaring integers keeps them integers, so no decimal point appears.
abs:∣x∣=x for x≥0, so the list is just the input again: [1, 4, 9, 16].
Notice the result is a dictionary of plain lists keyed 'sqrt', 'square', 'abs', and that only the square-root entry changes number type.
NumPy arrays are the foundation for efficient numerical computing in Python, enabling vectorized operations that apply functions element-wise across entire arrays without explicit loops. This leverages compiled C code for speed, avoiding Python's interpreter overhead.
Key NumPy ufuncs (universal functions) for this problem:
np.sqrt(x): Computes x for each element x
arr ** 2: Element-wise squaring (equivalent to np.square(arr))
Rounding: np.round(arr, 2) returns floats rounded to 2 decimals
Vectorization principle: Operations broadcast across arrays in O(n) time, where n is array length, making NumPy ideal for mathematical transformations on large datasets.
2. Algorithm Approach
Use element-wise ufunc application followed by dictionary construction:
Apply ufuncs directly to input array arr
Round sqrt results: np.round(np.sqrt(arr), 2)
Convert results to lists
Package into dict {"sqrt":..., "square":..., "abs":...}
This is a pure functional mapping: arr↦{f1(\text{arr}),f2(\text{arr}),f3(\text{arr})} where f1=⋅, f2=(⋅)2, f3=∣⋅∣.
No iteration needed—NumPy handles parallelism internally.