B
Brian Blais
Hello,
Most of my experience is with Matlab/Octave, so I am a Python newbie (but enjoying
it! )
There are a lot of things that I do in Matlab that I'd like to know the proper way to
do in Python. Here are a few:
MATLAB:
% example vectors
a=1:10;
b=-5:.1:5;
% set all the values above 5 equal to 6
idx=find(a>5);
a(idx)=6;
% extract elements
idx=find(b>0)
b=b(idx);
% meshgrid...usually to go through all possibly values of a parameter
[x,y]=meshgrid(1:10,-5:.1:5)
x=x); y=y);
for i=1:length(x)
% do something with x(i) and y(i)
end
I'm sure there are more, but these jump out at me as I'm going. It seems as if the
idx=find() stuff can be done with Numeric.nonzeros(), but you can't index with that, like
a=Numeric.arange(1,11,1)
idx=Numeric.nonzeros(a)
a=a[idx] % doesn't work
and what about meshgrid? Do I use the fromfunction() in some way? Is there a
resource that goes through comparisons like this?
thanks,
Brian Blais
Most of my experience is with Matlab/Octave, so I am a Python newbie (but enjoying
it! )
There are a lot of things that I do in Matlab that I'd like to know the proper way to
do in Python. Here are a few:
MATLAB:
% example vectors
a=1:10;
b=-5:.1:5;
% set all the values above 5 equal to 6
idx=find(a>5);
a(idx)=6;
% extract elements
idx=find(b>0)
b=b(idx);
% meshgrid...usually to go through all possibly values of a parameter
[x,y]=meshgrid(1:10,-5:.1:5)
x=x); y=y);
for i=1:length(x)
% do something with x(i) and y(i)
end
I'm sure there are more, but these jump out at me as I'm going. It seems as if the
idx=find() stuff can be done with Numeric.nonzeros(), but you can't index with that, like
a=Numeric.arange(1,11,1)
idx=Numeric.nonzeros(a)
a=a[idx] % doesn't work
and what about meshgrid? Do I use the fromfunction() in some way? Is there a
resource that goes through comparisons like this?
thanks,
Brian Blais