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?
> 

in my local branch (http://github.com/mattpap/sympy-polys/commits/polys8)
I had to extend lambdify(), so with the extension you can do the following:

In [1]: from sympy.printing.lambdarepr import LambdaPrinter 

In [2]: class ImaginaryPrinter(LambdaPrinter):
   ...:     def _print_ImaginaryUnit(self, expr):
   ...:         return "1j"
   ...:     
   ...:     

In [3]: N = Matrix([[1+I,2],[3,4]])

In [4]: g = lambdify((), N, modules='numpy', printer=ImaginaryPrinter)

In [5]: g()
Out[5]: 
 [[ 1.+1.j  2.+0.j]
  [ 3.+0.j  4.+0.j]]

In [6]: type(_)
Out[6]: <class 'numpy.core.defmatrix.matrix'>

> 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

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to