[Numpy-discussion] Are there command similar as Matlab find command?
Hi, I am trying to find a command in numpy or python that perform similar function as Matlab find command. It will return the indexes of array that satisfy a condition. So far I have not found anything. Thanks Frank Date: Thu, 25 Sep 2008 09:51:46 +0200 From: [EMAIL PROTECTED] To: numpy-discussion@scipy.org Subject: Re: [Numpy-discussion] loadtxt error 2008/9/24 frank wang [EMAIL PROTECTED]: Thank you very much for all of you. I have downloaded the binary version 1.2rc and it fixed the problem. My special thanks to the person who created the window binary version for users who do not know or do not have the capacity to build the numpy from source. That would be David Cournapeau -- one of the few brave enough to venture there. Cheers Stéfan ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion _ Stay up to date on your PC, the Web, and your mobile phone with Windows Live. http://clk.atdmt.com/MRT/go/msnnkwxp1020093185mrt/direct/01/___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Are there command similar as Matlab find command?
On Mon, Sep 29, 2008 at 5:32 PM, frank wang [EMAIL PROTECTED] wrote: Hi, I am trying to find a command in numpy or python that perform similar function as Matlab find command. It will return the indexes of array that satisfy a condition. So far I have not found anything. If you're familiar with MATLAB, look here: http://www.scipy.org/NumPy_for_Matlab_Users In the table you'll find the following equivalence: find(a0.5) - where(a0.5) -- Nathan Bell [EMAIL PROTECTED] http://graphics.cs.uiuc.edu/~wnbell/ ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Are there command similar as Matlab find command?
frank wang wrote: Hi, I am trying to find a command in numpy or python that perform similar function as Matlab find command. It will return the indexes of array that satisfy a condition. So far I have not found anything. There are several ways to do this, but what are you trying to do? Non-zero on the boolean array resulting from the condition is the most direct way: (a30).nonzero() where(a30) This returns a tuple of indices of length nd, where nd is the number of dimensions of a. (i.e. for 1-d case you need to extract the first element of the tuple to get the indices you want). But, if you are going to use these indices to access elements of the array, there are better ways to do that: a[a30] compress(a30, a) etc. -Travis ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Are there command similar as Matlab find command?
Thanks for the help. It seems that the where command has problem when I tried to run it in the debug mode. It does not return any thing such as: (Pdb) aa=array([1,2,3,4] (Pdb) where(aa2) stdin(1)module() c:\dhg\docsis\lab_test\parseadc.py(70)parsempeg()- bb=array(fid).astype('int') (Pdb) It does not return any result. Frank Date: Mon, 29 Sep 2008 16:48:23 -0500 From: [EMAIL PROTECTED] To: numpy-discussion@scipy.org Subject: Re: [Numpy-discussion] Are there command similar as Matlab find command? frank wang wrote: Hi,I am trying to find a command in numpy or python that perform similar function as Matlab find command. It will return the indexes of array that satisfy a condition. So far I have not found anything. There are several ways to do this, but what are you trying to do? Non-zero on the boolean array resulting from the condition is the most direct way: (a30).nonzero() where(a30) This returns a tuple of indices of length nd, where nd is the number of dimensions of a. (i.e. for 1-d case you need to extract the first element of the tuple to get the indices you want). But, if you are going to use these indices to access elements of the array, there are better ways to do that: a[a30] compress(a30, a) etc. -Travis ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion _ Want to do more with Windows Live? Learn “10 hidden secrets” from Jamie. http://windowslive.com/connect/post/jamiethomson.spaces.live.com-Blog-cns!550F681DAD532637!5295.entry?ocid=TXT_TAGLM_WL_domore_092008___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Are there command similar as Matlab find command?
On Mon, Sep 29, 2008 at 20:16, frank wang [EMAIL PROTECTED] wrote: Thanks for the help. It seems that the where command has problem when I tried to run it in the debug mode. It does not return any thing such as: (Pdb) aa=array([1,2,3,4] (Pdb) where(aa2) stdin(1)module() c:\dhg\docsis\lab_test\parseadc.py(70)parsempeg() - bb=array(fid).astype('int') (Pdb) It does not return any result. It's worth noting that that is not a debug mode of the interpreter; it's the pdb debugger, a separate piece of software which is used in an entirely different manner. Specifically, pdb has a where command which is what you are getting here. (Pdb) ?where w(here) Print a stack trace, with the most recent frame at the bottom. An arrow indicates the current frame, which determines the context of most commands. 'bt' is an alias for this command. -- 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 ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Are there command similar as Matlab find command?
Hi, Robert, Thank you very much for clarification of this. I really do not know the difference of debug mode and the pdb debugger. To me, it seems that pdb is only way to debug the python code. How do the expert of numpy/python debug their code? Are there any more efficient way to debug the code in python world? I used to use matlab which comes with a nice debugger. But now I really want to try the open source software and I found python/numpy is a nice tool. The only lagging piece of python/numpy comparing with matlab is the powerful debuggign capability. Onece again, I really appreciate the help I got from the forum. Frank Date: Mon, 29 Sep 2008 20:22:14 -0500 From: [EMAIL PROTECTED] To: numpy-discussion@scipy.org Subject: Re: [Numpy-discussion] Are there command similar as Matlab find command? On Mon, Sep 29, 2008 at 20:16, frank wang [EMAIL PROTECTED] wrote: Thanks for the help. It seems that the where command has problem when I tried to run it in the debug mode. It does not return any thing such as: (Pdb) aa=array([1,2,3,4] (Pdb) where(aa2) stdin(1)module() c:\dhg\docsis\lab_test\parseadc.py(70)parsempeg() - bb=array(fid).astype('int') (Pdb) It does not return any result. It's worth noting that that is not a debug mode of the interpreter; it's the pdb debugger, a separate piece of software which is used in an entirely different manner. Specifically, pdb has a where command which is what you are getting here. (Pdb) ?where w(here) Print a stack trace, with the most recent frame at the bottom. An arrow indicates the current frame, which determines the context of most commands. 'bt' is an alias for this command. -- 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 ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion _ Stay up to date on your PC, the Web, and your mobile phone with Windows Live. http://clk.atdmt.com/MRT/go/msnnkwxp1020093185mrt/direct/01/___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Are there command similar as Matlab find command?
frank wang wrote: Hi, Robert, Thank you very much for clarification of this. I really do not know the difference of debug mode and the pdb debugger. That's totally different in principle. Debug mode means your code is compiled/interpreted differently to keep as much information as possible, even if it makes your code run slower. But it can still be run under the normal running environment (python interpreter in python's case). A debugger is a *different* running environment, often specialized for introspection, to do things not normally possible. Here, pdb. Generally, for a debugger to be useful, your code has to be interpreted/run in debug mode, though (but does not have to be in principle; just less information). Running under a debugger can also mean your code run significantly slower depending on what you do. If you are familiar with C, debug mode in python is like compiling with -g -DDEBUG with gcc, and debugger is running gdb. To me, it seems that pdb is only way to debug the python code. How do the expert of numpy/python debug their code? Are there any more efficient way to debug the code in python world? I used to use matlab which comes with a nice debugger. It depends on the kind of bugs. In python, the print method is much more powerful than in C because you can inspect many things (you can even go into the stack to know which function called any entry point, for example, although the debugger makes it a bit easier I guess). Personally, I rarely if ever use the python debugger. cheers, David ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Are there command similar as Matlab find command?
2008/9/30 frank wang [EMAIL PROTECTED]: I really do not know the difference of debug mode and the pdb debugger. To me, it seems that pdb is only way to debug the python code. How do the expert of numpy/python debug their code? Are there any more efficient way to debug the code in python world? I used to use matlab which comes with a nice debugger. But now I really want to try the open source software and I found python/numpy is a nice tool. The only lagging piece of python/numpy comparing with matlab is the powerful debuggign capability. I think you will find that the debugger, pdb, is a good analog to matlab's debugging mode. The way I usually debug a piece of code looks something like: [in window A] edit foomodule.py to add a function frobnicate() [in window B, which has a running ipython session] import foomodule reload(foomodule) frobnicate() some exception happens %pdb frobnicate() exception happens again (pdb) print some_variable 47 [in window A] wait a minute, some_variable should be 13 at this point... edit foomodule.py to fix the bug [in window B] reload(foomodule) frobnicate() 21 Alternatively, I write a test_foomodule.py, which contains a suite of unit tests. I run these tests and get dropped into a debugger when one fails, and I try to track it down. The main problem you ran into is that the debugger is not just any old python prompt. It has its own commands. It also, confusingly, will accept python commands, as long as they don't conflict with an internal command. I got into the habit of, when I wanted to run some python thing, writing (pdb) p 17+13 rather than just (pdb) 17+13 If you had simply written (pdb) p where(a13) everything would have been fine. Anne ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion