[SciPy-User] convertin from octave/ matlab to scipy

eat e.antero.tammi at gmail.com
Fri Feb 19 08:02:13 EST 2010


> def t1():
>     m, n = 12, 123456
>     D = random.randn(m, n)
> 
>     def f(X):
>         return sqrt(sum(X**2, 0))
> 
>     print norm(f(D) - zm(f, D))
>     #or ?
>     #g = lambda D: zm(f, D)
>     #print norm(f(D)- g(D))
> 
> def zm(f, D):
>    m = mean(D, 1)[:, None]
>    return f(D- m)
Exactly what I was looking for, just couldn't figure it out myself.

Originally I planned to make the conversion mechanically, but your code gives 
me more toughts. I'll better learn python/ scipy a bit more first inorder to 
produce more readable code.

Thanks a lot,
eat





More information about the SciPy-User mailing list