Hi, On Fri, Apr 02, 2010 at 09:03:58AM -0700, wflynny wrote: > Hi! > > Quick question. I am struggling with what I think is a pretty trivial > problem. Say I have a 2x2 matrix of numbers of the form x+I*y where x > and y are doubles. Is there anyway to convert these numbers to the > form x+1j*y (I want to use numpy to calculate some eigenvalues)? Here > is an example: > > In [1]: from sympy import I > > In [2]: e = 1+I > > In [3]: e.subs(I,1j) > Out[3]: 1 + I > > In [4]: e.subs(I,numpy.complex(0,1)) > Out[4]: 1 + I > > Nothing I am trying seems to work. Is there something I am missing? >
that's an interesting question. In principle you can't do e.subs(I, 1j) or whatever similar because 1j (or equivalent) is sympified (converted) to I and no substitution occurs. The tool to solve your problem should be lambdify() function, e.g.: In [1]: M = Matrix([[1,2],[3,4]]) In [2]: f = lambdify((), M, modules='numpy') In [3]: f() Out[3]: [[1 2] [3 4]] In [4]: type(_) Out[4]: <class 'numpy.core.defmatrix.matrix'> Unfortunately lambdify() has problem with the imaginary unit: In [5]: N = Matrix([[1+I,2],[3,4]]) In [6]: g = lambdify((), N, modules='numpy') In [7]: g() --------------------------------------------------------------------------- NameError Traceback (most recent call last) /home/matt/repo/git/sympy/<ipython console> in <module>() /home/matt/repo/git/sympy/<string> in <lambda>() NameError: global name 'I' is not defined This is rather trivial issue to fix. > Thanks! > > Bill > > -- > You received this message because you are subscribed to the Google Groups > "sympy" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/sympy?hl=en. > -- Mateusz
signature.asc
Description: This is a digitally signed message part
