Join Our 5-Week ML/AI Engineer Interview Bootcamp 🚀 led by ML Tech Leads at FAANGs
Sinusoidal encoding turns a cyclic feature (like hour-of-day) into two smooth features using sine and cosine so models don’t treat the “end” and “start” as far apart. You’ll implement this encoding for an array of cyclic values and return the encoded features as NumPy arrays.
Implement the function
Rules:
np.sin, np.cos, np.pi).Output:
| Argument | Type |
|---|---|
| period | float |
| values | np.ndarray |
| Return Name | Type |
|---|---|
| value | tuple |
Use NumPy sin/cos; return NumPy arrays.
No sklearn/feature-engineering helper libraries.
Output tuple of np.ndarrays: (sin_arr, cos_arr).
Map each value onto the unit circle by converting it to an angle in radians: angle = 2π * x / period.
Use NumPy element-wise operations to compute angle, sin(angle), and cos(angle) for the entire array at once.
Use np.pi for π, and ensure your input is treated as a NumPy array (which it is). Return np.sin(angles), np.cos(angles).