Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting different answers with MATLAB and Python norm functions

I am getting two vastly different answers with regards to simple matrix norms when comparing the MATLAB and Python functions.

Let

R =

    0.9940    0.0773   -0.0773
   -0.0713    0.9945    0.0769
    0.0828   -0.0709    0.9940

Then in MATLAB:

>> norm(R)

ans =

     1

But in Python

from scipy.linalg import norm
import numpy as np

print norm(R),np.linalg.norm(R)

1.73205080757 1.73205080757

where

print scipy.__version__,np.__version__
0.14.0 1.9.0

How did I manage to so comprehensively screw that up?

like image 784
Astrid Avatar asked Nov 04 '25 15:11

Astrid


1 Answers

Python is returning the Frobenius norm. You can do this in MATLAB with:

>> norm(R,'fro')
ans =
          1.73203140271763

By default, norm gives the 2-norm (norm(R,2)).

like image 130
chappjc Avatar answered Nov 06 '25 06:11

chappjc



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!