[SciPy-user] how to convert this matlab command to scipy?

Damian Eads eads@soe.ucsc....
Fri May 16 02:05:19 CDT 2008

zhang chi wrote:
>     How to convert this matlab command (Yf12(:) = CYf(mask);) to scipy 
> command?
> where
> size(CYf) = (128 1)
> size(mask) = (128 128)

Like Robert said, you should be more specific about what you want to do, 
and preferably describe it in English.

The poster's code will not work in MATLAB for the code specified.

# L=rand(128,128)>0.5;   % generate a random 128x128 matrix of logicals
# Q=rand(1,128);         % generate a random 1x128 matrix of doubles
# Q(L)                   %
??? Index exceeds matrix dimensions.

However, if we reverse the size specifications so that L is 1x128 and Q 
is 128x128, it works. After deciphering the output, Q(L) returns values 
Q(1,i) in the first column where mask(i) is true (e.g. Q(L) and Q(1,L)' 
are equivalent). However, Q can be longer, in which case the mask is 
applied to the succeeding columns. However, given an incorrect code 
snippet without a problem description, it is not worth speculating what 
the poster is trying to do.


More information about the SciPy-user mailing list