#C12445. 2D Array Normalization

    ID: 41873 Type: Default 1000ms 256MiB

2D Array Normalization

2D Array Normalization

You are given a 2D array represented by n rows and m columns. Your task is to implement two functions:

  • create_array: Convert the given list of lists (matrix) into a 2D array.
  • normalize_array: Normalize the array column-wise such that for each column, the normalized value is computed using the formula: $$x' = \frac{x - \mu}{\sigma}$$, where $$\mu$$ is the mean of the column and $$\sigma$$ is the standard deviation of the column. If a column has zero variance (i.e. $$\sigma = 0$$), treat $$\sigma$$ as 1 to avoid division by zero.

The input is provided via standard input and the output must be printed to standard output. First, print the original array, then a blank line, and then the normalized array. Each row of the array should be printed on a separate line with the elements separated by a single space.

Note: All formulas are represented in LaTeX format.

inputFormat

The first line of input contains two integers n and m, representing the number of rows and columns of the array respectively. This is followed by n lines, each containing m space-separated numbers representing the elements of the row.

outputFormat

Output consists of the following lines:

  1. A line with the text "Original array:".
  2. n lines, each line showing the corresponding row of the original array with its elements separated by a single space.
  3. A blank line.
  4. A line with the text "Normalized array:".
  5. n lines, each line showing the corresponding row of the normalized array. Each normalized value should be printed with 8 decimal places and separated by a single space.
## sample
3 3
1 2 3
4 5 6
7 8 9
Original array:

1 2 3 4 5 6 7 8 9

Normalized array: -1.22474487 -1.22474487 -1.22474487 0.00000000 0.00000000 0.00000000 1.22474487 1.22474487 1.22474487

</p>