Hi again,
this seems to be more general of a problem than stated here below. It
appears as if data with types numpy.ndarray and numpy.float64 do not
mix well with types like RealNumber etc that are the sage default.
How do I ensure that everything I use are standard scipy numerical
types ? I have put
RealNumber = scipy.float64
ComplexNumber = scipy.complex128
at the beginning of my script.
In order to get past a routine, I need to add a lot of casting; an
example is:
def lambd_anal(D,beta,delta,n,dt,k):
eta = scipy.arange(1,n+1,dtype=scipy.float64)
h = 1./(n+1)
l = 2*D/h**2 * (scipy.cos(2*scipy.pi*h*eta)-1)+scipy.sqrt(-1) *
beta/h * scipy.sin(2*scipy.pi*h*eta)
l = scipy.array(l,dtype=scipy.complex128)
lambd = (1.-(1.+dt*l)**k)/(1.-1./(1.-l*k*dt))
lambd = scipy.array(lambd,dtype=scipy.complex128)
return scipy.real(lambd),scipy.imag(lambd)
But I still get errors of the type ...
File "/Users/giovanni/.sage/sage_notebook/worksheets/admin/1/code/
24.py", line 9, in A_impl
T = scipy.linalg.inv(I_h-A_h*k*dt)
TypeError: unsupported operand type(s) for *: 'numpy.ndarray' and
'numpy.float64'
In which A_h is an ndarray and k and dt are float64 numbers.
I love the sage notebook interface, but I would adore it to behave as
an ipython -pylab shell; or at the least, some guide of main
differences between python+scipy and sage.
Any help would greatly be appreciated.
Giovanni
On Jun 4, 12:00 pm, Giovanni Samaey <[EMAIL PROTECTED]> wrote:
> Dear all,
>
> I am having a hard time figuring out how to use my existing modules
> that are written in scipy and use complex numbers. If they receive
> input that has a been generated within sage, I cannot simply use
> scipy.real and scipy.imag to split the complex numbers.
>
> I found that copying all my function definitions into sage partly
> resolves the problem -- I then need to
> 1) define ComplexNumber=scipy.complex128 and RealNumber=scipy.float64
> 2) whenever I use my variables together with typed numbers, such as
> "1.", I need to cast the result to scipy.complex128 using the
> scipy.array function before splitting in real and imaginary part.
> 3) I also cannot use the 1j syntax of scipy, so I write sqrt(-1).
>
> However,I didn't figure out yet how to use a whole function in a
> module which is imported into sage, and compute an array that will be
> split in a real and imaginary part inside a routine of the module...
>
> I looked at the reference manual but couldn't find a clue. Is this a
> common problem ?
>
> Best wishes, and thanks !
>
> Giovanni
--~--~---------~--~----~------------~-------~--~----~
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/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---