From: <jou...@gm...> - 2004-11-14 16:09:03
|
Hi, In Matlab, the command [i,j] =3D find(mat >=3D 3) causes i and j to hold the indices where the condition holds. (If there is only one output argument, it will hold indices to the flattened version of the condition.) Matplotlib's mlab.find() seems to work for one-dimensional arrays only. Here's what I'm using to emulate Matlab's find; it only seems to work with Numeric, not numarray, and I have no idea whether this is an efficient way to achieve the goal. I was going to suggest that the utility be included in matplotlib, but perhaps it should then be generalized to work with numarray as well. I wonder if anyone has any ideas on how to do this? I'm a newcomer to matplotlib (and Numeric, etc.), so please do point out if there is a simpler way to achieve the effect of Matlab's find. def find(condition): """ Return the indices where condition is true. For arrays of N>=3D2 dimensions, returns a tuple T of N arrays such that the condition is true at indices (T[0][i],...,T[N-1][i]). """ sh =3D condition.shape if len(sh) =3D=3D 1: return nonzero(condition) idx =3D indices(sh) cond =3D ravel(condition) return tuple([compress(cond, ravel(idx[i]))=20 for i in range(len(sh))]) --=20 Jouni K Sepp=E4nen http://www.iki.fi/jks |
From: <jou...@gm...> - 2004-11-14 18:36:50
|
On Sun, 14 Nov 2004 18:08:59 +0200, Jouni K Sepp=E4nen <jou...@gm...> wrote: > > Here's what I'm using to emulate Matlab's find; it only seems to work > with Numeric, not numarray Oops - actually it seems that after from matplotlib.numerix import ravel, indices, compress the function works whether numerix is using numarray or Numeric. Making a special case of single-dimensional inputs is not very elegant, but doing otherwise would break compatibility with the existing mlab.find; and I guess there is no way in Python of emulating Matlab's detection of the number of output arguments. --=20 Jouni K Sepp=E4nen http://www.iki.fi/jks |
From: Darren D. <dd...@co...> - 2004-11-14 21:49:34
|
Hi Jouni, Jouni K Sepp=E4nen wrote: >On Sun, 14 Nov 2004 18:08:59 +0200, Jouni K Sepp=E4nen ><jou...@gm...> wrote: > =20 > >>Here's what I'm using to emulate Matlab's find; it only seems to work >>with Numeric, not numarray >> =20 >> > >Oops - actually it seems that after > >from matplotlib.numerix import ravel, indices, compress > >the function works whether numerix is using numarray or Numeric. > >Making a special case of single-dimensional inputs is not very >elegant, but doing otherwise would break compatibility with the >existing mlab.find; and I guess there is no way in Python of emulating >Matlab's detection of the number of output arguments. > =20 > I looked at this a while back, and came to the same conclusion. Thats an=20 interesting question, can Python determine the number of output=20 arguments? I dont know of a convenient function call, but it seems like=20 that information must exist somewhere. I'll ask at c.l.p. Darren |
From: <na...@te...> - 2004-11-15 03:39:10
|
Hello, I think I've found a bug in mathtext - sorry if this appeared before, I couldn't find it in the list archives. When I try: xlabel(r"$-(\Omega_a^' + \Omega_a)$") I don't get what I expected. The label shows -\Omega_a and stops there. Further tests showed that, whenever I try a single quote in a mathtext string, the text is not rendered from the quote on. This might not be a bug, I might be doing something wrong. If this is the case, please tell me how to do it right. Thanks in advance. --- José Alexandre Nalon na...@te... |
From: Darren D. <dd...@co...> - 2004-11-15 03:56:45
|
> xlabel(r"$-(\Omega_a^' + \Omega_a)$") > > I don't get what I expected. The label shows -\Omega_a and stops > there. Further tests showed that, whenever I try a single quote > in a mathtext string, the text is not rendered from the quote on. > > This might not be a bug, I might be doing something wrong. If > this is the case, please tell me how to do it right. > try replacing ^' with ^\prime Darren |
From: John H. <jdh...@ac...> - 2004-11-15 04:17:59
|
>>>>> "Jos=E9" =3D=3D Jos=E9 Alexandre Nalon <na...@te...> writes: Jos=E9> Hello, I think I've found a bug in mathtext - sorry if this Jos=E9> appeared before, I couldn't find it in the list archives. Jos=E9> When I try: Jos=E9> xlabel(r"$-(\Omega_a^' + \Omega_a)$") Jos=E9> I don't get what I expected. The label shows -\Omega_a and Jos=E9> stops there. Further tests showed that, whenever I try a Jos=E9> single quote in a mathtext string, the text is not rendered Jos=E9> from the quote on. Jos=E9> This might not be a bug, I might be doing something Jos=E9> wrong. If this is the case, please tell me how to do it Jos=E9> right. I don't believe your use of ' is valid TeX. Try Omega_a^\prime Jos=E9> Thanks in advance. Sure thing, JDH |