[SciPy-User] convertin from octave/ matlab to scipy
eat
e.antero.tammi@gmail....
Thu Feb 18 15:58:00 CST 2010
Hi,
I'll just have started to study and learn the python/ scipy.
I have written some inhouse (exploratory) data analysis
octave/ matlab toolboxes/ packages that I now like to convert
to python/ scipy.
I do have googled and skimmed bunch of documents, but still
I'll like to have experts opinion how to convert this (typical)
octave/ matlab indicies idiom to scipy:
"""
a simple minded conversion of idiom 1 from octave(or matlab)
<ocode>
function t1
m= 12; n= 123456; D= randn(m, n);
f= @(X) sqrt(sum(X.^2)); g= @(D) zm(f, D);
norm(f(D)- g(D))
function D= zm(f, D)
m= mean(D, 2); D= f(D- m(:, ones(1, size(D, 2))));
</ocode>
to scipy:
"""
from scipy import *
from numpy.linalg import norm #???
def zm(f, D):
a= vstack(range(D.shape[0]))* ([1]* D.shape[1]);
m= mean(D, 1); return f(D- m[a])
m= 12; n= 123456; D= random.randn(m, n);
f= lambda X: sqrt(sum(X**2, 0)); g= lambda D: zm(f, D)
print norm(f(D)- g(D))
I think my main question is:
do we have in scipy some 'under the hood' functionality, which
allows us not to repmat the constant vector (m)?
(Code like above is handled quite well in matlab where
(e(matlab)/ e(octave)<~ .1), compared to (e(scipy)/ e(octave)<~ .5),
where e(x) is some measure of the execution time in x.)
More information about the SciPy-User
mailing list