Shift and Scale Array to Target Range

Data Preparation & Feature Engineering DS practice problem on Onlearn.

Difficulty: easy.

Topics: Shift and Scale Array to Target Range, Min-Max Scaling, Z-Score Standardization, Broadcasting, Linear Transformation, Outlier Clipping, Data Preprocessing, Statistical Analysis, Numerical Computing, Feature Engineering, Pipeline Orchestration, Feature Scaling, Data Normalization, Array Manipulation, Distribution Transformation, Vectorized Operations.

Write a Python function convert range that shifts and scales the values of a NumPy array from their original range $[a, b]$ (where $a=\min(x)$ and $b=\max(x)$) to a new target range $[c, d]$. Your function should work for both 1D and 2D arrays, returning an array of the same shape, and only use NumPy. Return floating point results, and ensure you use the correct formula to map the input interval to the output interval.