[SciPy-User] convertin from octave/ matlab to scipy
Fri Feb 19 08:35:52 CST 2010
On Fri, Feb 19, 2010 at 8:02 AM, eat <firstname.lastname@example.org> wrote:
>> 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.
I often translate matlab functions with a simple structure (even if
the calculation is complicated) quite literally to python/numpy/scipy.
However, for the big structure and control flow using, for example,
classes is a huge advantage compared to matlab. (Although matlab is
also improving its support of classes, which I haven't used yet.)
A good book for python (for scienc) that uses numpy is very helpful.
And I found and still find it very informative to read code written by
> Thanks a lot,
> SciPy-User mailing list
More information about the SciPy-User