# Ticket #1659(closed enhancement: worksforme)

Opened 5 years ago

## Add a complex128 method for conversion of symbolic (and other?) expressions to numpy's 128-bit complex type

Reported by: Owned by: was robertwb major sage-duplicate/invalid/wontfix coercion N/A

### Description

```rishi_: I use scipy very often. To use complex number I have to use the following statement:  sage: a=numpy.complex128(complex(2+3*I)). Is it not possible to avoid 2 conversions?
[12:29pm] mabshoff: hungry? *ducks*
[12:29pm] ondrej: mabshoff - like a small dog?
[12:29pm] mabshoff: yes. a young dog.
[12:29pm] wstein-1658: We could add a method (2+3*I).complex128().
[12:29pm] wstein-1658: Want that?
[12:29pm] wstein-1658: Is I symbolic, by the way?
[12:29pm] rishi_: yes
[12:30pm] wstein-1658: Do you want to avoid two conversions because of speed or code cleaness?
[12:30pm] wstein-1658: Probably clean-ness.
[12:30pm] rishi_: cleaness
```

## Change History

### comment:1 Changed 5 years ago by was

A temporary workaround (and almost the fix):

```sage: import sage.calculus.calculus
sage: def complex128(self): import numpy; return numpy.complex128(complex(self))
....:
sage: sage.calculus.calculus.SymbolicExpression.complex128 = complex128
sage:
sage: (3 + 2*I).complex128()
(3+2j)
```

### comment:2 Changed 3 years ago by mhansen

• Status changed from new to closed
• Report Upstream set to N/A
• Resolution set to worksforme
• Milestone changed from sage-4.5.3 to sage-duplicate/invalid/wontfix

This now works:

```----------------------------------------------------------------------
| Sage Version 4.5.2, Release Date: 2010-08-05                       |
| Type notebook() for the GUI, and license() for information.        |
----------------------------------------------------------------------