Z-Score Standardize

Xem dạng PDF

Gửi bài giải

Điểm: 100,00
Giới hạn thời gian: 2.0s
Giới hạn bộ nhớ: 256M

Tác giả:
Dạng bài
Ngôn ngữ cho phép
Python

Task

Given a vector x of length n, standardize it to have mean 0 and population standard deviation 1:

z_i = (x_i - μ) / σ,  μ = mean(x),  σ = std(x, ddof=0)

Use population standard deviation (divide by n, not n-1). If σ = 0 (all values equal), return a vector of all zeros.

Input

  • Line 1: integer n
  • Line 2: n space-separated floats

Output

n space-separated floats, each with 10 significant digits.

Example

Input:

4
1 2 3 4

Output:

-1.341640786 -0.4472135955 0.4472135955 1.341640786

Scaffolding

def zscore(x: list[float]) -> list[float]: ...

Hint

Guard against std == 0 before dividing. Use ddof=0 (population), not ddof=1.


Bình luận

Hãy đọc nội quy trước khi bình luận.


Không có bình luận tại thời điểm này.