From: Darren D. <dd...@co...> - 2004-11-15 06:27:08
|
Hi John, > >> I guess there is no way in Python of emulating Matlab"s > >> detection of the number of output arguments. > > Darren> I just got a response from c.l.p. Somebody remembered > Darren> seeing this at ASPN: > Darren> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/284742 > > Darren> expecting() is the workhorse, equivalent to Matlab's > Darren> nargout: > > Darren> import inspect,dis > > Hi Darren, > > Wow, I didn't know this was possible in python. Does it work under > python2.2? The ASPN page says it has been tested on 2.3.3. I dont have a 2.2 installation handy to check it. > > Perhaps you would like to write up nargin and nargout function with > some doc strings and send them my way? I could add them to the matlab > interface. But we need to make sure they are 2.2 compliant. I will give it a shot in my free time, but without getting into it, my next month is pretty full. > > As an aside, do we need nargout to make "find" work like matlab's? > Isn't it enough just to check the shape of the input array and > processing it one way for 1D arrays and another way for 2D arrays? > The problem is that mlab.find() is currently a thin wrapper around a numeric or numarray method, which only works for 1D arrays. ravelling the arrays passed to find would make it easy to continue using the method called by find(), but I had trouble figuring out how to process the 1xM results of that method back into an NxM or MxN array that could be used to index an N-D array. It would be nice to be able to address Numeric and numarray with a single index. Matlab does this. For example, if a=array([[1,2],[3,4]]), a[0] would be 1, a[1] would be 3 (Matlab's convention, again if memory serves.) -- Darren |