After meeting the first condition, I need to divide every number by standard deviation.
Adjust data vector to have certain variance
-
14-04-2022 - |
Question
I have a set of integers x, 0<=x<=255 I need to transform this data in that way that :
- Average of values in set == 0
- Variance == 1
I can meet first condition with:
array arr[];
av = average(arr);
foreach(x in arr) { x = x - av;}
But I do not know, how to meet second one.
The best idea I have: Compute current variance and divide or multiply all integers by A to get closer to desired variance. Then A=A/2 and repeat until error is small.
(Resembles basic algorithm of estimating square root of x.)
Is there another (more efficient) way of achieving this?
La solution
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow