how to convert this matlab command to scipy?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

how to convert this matlab command to scipy?

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

_______________________________________________
SciPy-user mailing list
[hidden email]
http://projects.scipy.org/mailman/listinfo/scipy-user
Reply | Threaded
Open this post in threaded view
|

Re: how to convert this matlab command to scipy?

Robert Kern-2
On Thu, May 15, 2008 at 7:18 PM, zhang chi <[hidden email]> wrote:
> hi
>     How to convert this matlab command (Yf12(:) = CYf(mask);) to scipy
> command?
> where
> size(CYf) = (128 1)
> size(mask) = (128 128)

Please describe the operation you want to perform in English. I don't
speak fluent Matlab.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
 -- Umberto Eco
_______________________________________________
SciPy-user mailing list
[hidden email]
http://projects.scipy.org/mailman/listinfo/scipy-user
Reply | Threaded
Open this post in threaded view
|

Re: how to convert this matlab command to scipy?

Hoyt Koepke
In reply to this post by zhang chi
I have to say I haven't seen that particular operation in matlab
before.  Is mask a logical matrix or a matrix of indices?  If it's a
logical matrix, I really don't understand what it's trying to do.
If it's a matrix of indices, then you might get the same behavior in
numpy by using CYf[mask.ravel()] -- but I'm really not sure of this.
Normally, logical mask operations have to match shape exactly, and
index matrices are one dimensional....

--Hoyt



On Thu, May 15, 2008 at 5:18 PM, zhang chi <[hidden email]> wrote:

> hi
>     How to convert this matlab command (Yf12(:) = CYf(mask);) to scipy
> command?
> where
> size(CYf) = (128 1)
> size(mask) = (128 128)
>
> _______________________________________________
> SciPy-user mailing list
> [hidden email]
> http://projects.scipy.org/mailman/listinfo/scipy-user
>
>



--
+++++++++++++++++++++++++++++++++++
Hoyt Koepke
UBC Department of Computer Science
http://www.cs.ubc.ca/~hoytak/
[hidden email]
+++++++++++++++++++++++++++++++++++
_______________________________________________
SciPy-user mailing list
[hidden email]
http://projects.scipy.org/mailman/listinfo/scipy-user
Reply | Threaded
Open this post in threaded view
|

Re: how to convert this matlab command to scipy?

Damian Eads-2
In reply to this post by zhang chi
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
_______________________________________________
SciPy-user mailing list
[hidden email]
http://projects.scipy.org/mailman/listinfo/scipy-user