All problems

Mean Imputation

mediumPythonFeature Engineering

Some of Quillon Energy's meters drop a reading, and the column arrives with holes in it written as NA. Most models refuse the file outright rather than skip a hole, and deleting the whole row throws away every other column for that customer. So the holes are filled instead: each one takes the average of the readings that did turn up in this column. The holes themselves have no value and so take no part in working that average out, and the average is settled once over the whole column before any hole is filled -- a hole never influences the value of a later hole.

Task: Print the column with every hole filled.

Input

The first line holds one integer n, the number of entries. The second line holds the n entries separated by single spaces; each is either a number or the exact text NA. At least one entry is a real reading.

Output

One line holding all n entries in their original positions and order, separated by single spaces, each printed to 2 decimal places -- the real readings as well as the filled holes.

Example:

Input:
5
10 NA 20 NA 30

Output:
10.00 20.00 20.00 20.00 30.00

Sign in to solve this problem

Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.

Sign in

Discussion

Sign in to join the discussion — reading is open to everyone.

Loading comments…