[SciPy-user] how to convert this matlab command to scipy?
Damian Eads
eads at soe.ucsc.edu
Fri May 16 03:05:19 EDT 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.
Damian
More information about the SciPy-User
mailing list