Shyamkkhadka
Shyamkkhadka

Reputation: 1468

how to de-normalize values normalized by linalg.norm method of numpy?

I have an array

a = array([[ 3.55679502,  3.46622505],
           [ 1.03670334,  2.43254031],
           [ 1.12185975,  3.25257322]])

Now I normalized it with numpys linalg.norm method

norm_a = a/np.linalg.norm(a)

It gives normalized values in the range of (0,1) as

norm_a = array([[ 0.53930891,  0.52557599],
                [ 0.15719302,  0.36884067],
                [ 0.1701051 ,  0.49318044]])

Now, using norm_a, how can I recover original de-normalized matrix a?

Upvotes: 1

Views: 3257

Answers (2)

Divakar
Divakar

Reputation: 221524

You are basically scaling down the entire array by a scalar. The scaling factor has to be used for retrieving back. That scaling factor would be np.linalg.norm(a) and could be stored while computing the normalized values and then used for retrieving back a as shown in @EdChum's post. Another way would would be to store one of the elements off the original array a, say the first element and then use it with division against the corresponding element in the normalized array and get that scaling factor.

Thus, the other way would be -

a = norm_a*(a[0,0]/norm_a[0,0])

Again, if the chosen element is too small or big compared to the corresponding element in the normalized array, we might have slight differences. So, I am guessing using np.linalg.norm(a) would be the safest way here.

Upvotes: 1

EdChum
EdChum

Reputation: 393963

Do the opposite, simple maths really:

In [310]:    
norm_a * np.linalg.norm(a)

Out[310]:
array([[ 3.55679502,  3.46622505],
       [ 1.03670334,  2.43254031],
       [ 1.12185975,  3.25257322]])

Upvotes: 4

Related Questions