程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python solves the real problem of ccf-csp 202206-1 - normalization processing

編輯:Python

Students who want to check the real problems and solutions of other problems can go to check :CCF-CSP True problem with complete solution

Question number :202206-1 The title of the test question : normalization The time limit :500ms Memory limit :512.0MB Problem description :

Background

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 .

Problem description

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)

Input format

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 format

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).

The sample input

7
-4 293 0 -22 12 654 1000

Sample output

-0.7485510379073613
0.04504284674812264
-0.7378629047806881
-0.7966476369773906
-0.7057985054006686
1.0096468614303775
1.9341703768876082

Sample explanation

Average :a¯≈276.14285714285717

variance :D(a)≈140060.69387755104

Standard deviation :D(a)≈374.24683549437134

The subtasks

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.

Scoring method

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 .

Tips

  • 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


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved