Re: [Numpy-discussion] numpy.complex

2012-07-23 Thread Benjamin Root
On Monday, July 23, 2012, OC wrote: It's unPythonic just in the sense that it is unlike every other type constructor in Python. int(x) returns an int, list(x) returns a list, but np.complex64(x) sometimes returns a np.complex64, and sometimes it returns a np.ndarray, depending on what

[Numpy-discussion] numpy.complex

2012-07-21 Thread OC
Thank you for your answers. Chris Barker wrote: for consistency with the rest of the numpy types Then, why do numpy.complex64(A), numpy.complex128(A), numpy.uint8(A),... all work with arrays? It's very convenient that it works like this! It's awkward that numpy.complex(A) is the only one

Re: [Numpy-discussion] numpy.complex

2012-07-21 Thread Nathaniel Smith
On Sat, Jul 21, 2012 at 4:44 PM, OC oc-spa...@laposte.net wrote: Thank you for your answers. Chris Barker wrote: for consistency with the rest of the numpy types Then, why do numpy.complex64(A), numpy.complex128(A), numpy.uint8(A),... all work with arrays? It's very convenient that it

[Numpy-discussion] numpy.complex

2012-07-20 Thread OC
The syntax numpy.complex(A) seems to be the most natural and obvious thing a user would want for casting an array A to complex values. Expressions like A.astype(complex), array(A, dtype=complex), numpy.complex128(A) are less obvious, especially the last two ones, which look a bit far-fetched.

Re: [Numpy-discussion] numpy.complex

2012-07-20 Thread Chris Barker
On Fri, Jul 20, 2012 at 1:17 PM, OC oc-spa...@laposte.net wrote: numpy.complex is just a reference to the built in complex, so only works on scalars: What is the use of storing the complex() built-in function in the numpy namespace, when it is already accessible from everywhere? for

Re: [Numpy-discussion] numpy.complex

2012-07-20 Thread Pauli Virtanen
20.07.2012 22:17, OC kirjoitti: The syntax numpy.complex(A) seems to be the most natural and obvious thing a user would want for casting an array A to complex values. I think I disagree here -- that something like that works at all is rather surprising. Remember that numpy.complex,

[Numpy-discussion] numpy.complex

2012-07-18 Thread Molinaro Céline
Hello, In [2]: numpy.real(arange(3)) Out[2]: array([0, 1, 2]) In [3]: numpy.complex(arange(3)) TypeError: only length-1 arrays can be converted to Python scalars Are there any reasons why numpy.complex doesn't work on arrays? Should it be bug reported? Thanks for your help C. Molinaro

Re: [Numpy-discussion] numpy.complex

2012-07-18 Thread Henry Gomersall
On Wed, 2012-07-18 at 15:14 +0200, Molinaro Céline wrote: In [2]: numpy.real(arange(3)) Out[2]: array([0, 1, 2]) In [3]: numpy.complex(arange(3)) TypeError: only length-1 arrays can be converted to Python scalars Are there any reasons why numpy.complex doesn't work on arrays? Should it

Re: [Numpy-discussion] numpy.complex

2012-07-18 Thread Scott Sinclair
On 18 July 2012 15:14, Molinaro Céline celine.molin...@telecom-bretagne.eu wrote: Hello, In [2]: numpy.real(arange(3)) Out[2]: array([0, 1, 2]) In [3]: numpy.complex(arange(3)) TypeError: only length-1 arrays can be converted to Python scalars I think you're looking for the dtype keyword to

[Numpy-discussion] numpy.complex* functions do not call the __complex__ method

2008-09-25 Thread jason-sage
In creating an array of type numpy.complex128, I'm having problems passing in Sage types that should be considered complex numbers since they implement the standard __complex__ method. However, numpy doesn't recognize that. Here's a minimal example: In [1]: class MyNum: ...: def

Re: [Numpy-discussion] numpy.complex* functions do not call the __complex__ method

2008-09-25 Thread Neal Becker
[EMAIL PROTECTED] wrote: In creating an array of type numpy.complex128, I'm having problems passing in Sage types that should be considered complex numbers since they implement the standard __complex__ method. However, numpy doesn't recognize that. Here's a minimal example: I had tried

Re: [Numpy-discussion] numpy.complex* functions do not call the __complex__ method

2008-09-25 Thread jason-sage
Neal Becker wrote: [EMAIL PROTECTED] wrote: In creating an array of type numpy.complex128, I'm having problems passing in Sage types that should be considered complex numbers since they implement the standard __complex__ method. However, numpy doesn't recognize that. Here's a minimal