Question number :202206-1 The title of the test question : normalization The time limit :500ms Memory limit :512.0MB Problem description :Students who want to check the real problems and solutions of other problems can go to check :CCF-CSP True problem with complete solution
In machine learning , Data normalization is a common technique .
Adjust the data from various distributions to an average of 0、 The variance of 1 The standard distribution of , In many cases, it can effectively accelerate the training of the model .
It is assumed that the data to be processed is n It's an integer a1,a2,⋯,an.
The average of this set of data :
a¯=a1+a2+⋯+ann
variance :
D(a)=1n∑i=1n(ai−a¯)2
Use the following functions to process all data , Got n A floating point number f(a1),f(a2),⋯,f(an) That is, the average value is 0 And the variance is 1:
f(ai)=ai−a¯D(a)
Reading data from standard input .
The first line contains an integer n, Indicates the number of integers to be processed .
The second line contains space delimited n It's an integer , Sequential representation a1,a2,⋯,an.
Output to standard output .
The output, n That's ok , One float per line , The data normalized according to the above method are represented in turn f(a1),f(a2),⋯,f(an).
7
-4 293 0 -22 12 654 1000
-0.7485510379073613
0.04504284674812264
-0.7378629047806881
-0.7966476369773906
-0.7057985054006686
1.0096468614303775
1.9341703768876082
Average :a¯≈276.14285714285717
variance :D(a)≈140060.69387755104
Standard deviation :D(a)≈374.24683549437134
All test data guarantee n,|ai|≤1000, among |ai| Express ai The absolute value of .
And the input n It's an integer a1,a2,⋯,an Satisfy : variance D(a)≥1.
If each floating-point number you output is compared with the reference result , The absolute error is not greater than 10−4, Then the full score of the test point , Otherwise, no score .
C/C++: It is recommended to use double
Type storage floating point number , And use printf("%f", x);$$'
For the output .
Python: Use it directly print(x)
Just output .
Java: It is recommended to use double
Type storage floating point number , have access to System.out.print(x);
For the output .
The real question comes from : normalization
Interested students can go in and practice
Full Score solution :
n = int(input())
nums = list(map(int,input().split()))
a = sum(nums)/n
d = 0
for i in range(n):
d += (nums[i]-a)**2
d /= n
data = []
for i in range(n):
point = (nums[i]-a)/(d**0.5)
data.append(point)
for i in data:
print(i)
Running results :
ccf-csp Practice column
https://blog.csdn.net/weixin_53919192/category_11828479.html?spm=1001.2014.3001.5482https://blog.csdn.net/weixin_53919192/category_11828479.html?spm=1001.2014.3001.5482