Z-Score Standardization
EasyMachine LearningStatisticsArray
Description
Given an array of numbers, standardize each value to its z-score: subtract the mean and divide by the population standard deviation. If the standard deviation is 0, return an array of zeros. Round each result to 4 decimal places.
Examples
Input:
[2,4,6,8]Output:
[-1.3416,-0.4472,0.4472,1.3416]Explanation:
Each value is shifted by the mean 5 and divided by the standard deviation, so values above the mean become positive and values below the mean become negative.
Input:
[1,2,3]Output:
[-1.2247,0,1.2247]Explanation:
Each value is shifted by the mean 2 and divided by the standard deviation, so values above the mean become positive and values below the mean become negative.
Input:
[10,20,30,40]Output:
[-1.3416,-0.4472,0.4472,1.3416]Explanation:
Each value is shifted by the mean 25 and divided by the standard deviation, so values above the mean become positive and values below the mean become negative.
Constraints
- •
1 ≤ array length ≤ 10⁴