[Numpy-discussion] bug in numpy.ndarray?

Charles R Harris charlesr.harris at gmail.com
Sun May 8 20:23:10 EDT 2011


On Sun, May 8, 2011 at 3:15 PM, Paul Anton Letnes <
paul.anton.letnes at gmail.com> wrote:

> Hi,
>
> it seems that I have found a bug in numpy.ndarray. numpy 1.5.1, python
> 2.7.1 from macports on mac os x 10.6.7. I got the same error on Fedora 14
> with numpy 1.4.1 and python 2.7. Appending a [0] to the last line solves the
> problem.
>
> % python testcrash.py
>
>        [14:13:27 on 11-05-08]
> <type 'numpy.ndarray'> [ 12.+0.1j]
> <type 'numpy.ndarray'> [ 1.+0.1j]
> complex128
> Traceback (most recent call last):
>  File "testcrash.py", line 11, in <module>
>    A[0] = A[0] + (eps1 - eps2)
> TypeError: can't convert complex to float
>
>  % cat testcrash.py
> #!/usr/bin/env python
>
> import numpy
>
> A = numpy.zeros(10, dtype=numpy.complex128)
> eps1 = numpy.complex128([12.0 + 0.1j])
> eps2 = numpy.complex128([1.0 + 0.1j])
>

It's the brackets, numpy.complex128([1.0 + 0.1j]) is a 1d array, not a
scalar. The error message is less than helpful though.

<snip>

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20110508/e9ad0860/attachment.html>


More information about the NumPy-Discussion mailing list