On Sun, May 8, 2011 at 7:23 PM, Charles R Harris <charlesr.har...@gmail.com>wrote:
> > > On Sun, May 8, 2011 at 3:15 PM, Paul Anton Letnes < > paul.anton.let...@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. > > But the same pattern works fine with float64: In [2]: x = array([1.0, 2.0]) In [3]: y = array([10.0]) In [4]: x[0] = y # Works In [5]: a = array([1.0, 2.0], dtype=complex128) In [6]: b = array([10.0 + 1j]) In [7]: a[0] = b # Error --------------------------------------------------------------------------- TypeError Traceback (most recent call last) /Users/warren/<ipython console> in <module>() TypeError: can't convert complex to float Something is fishy about that. Warren > <snip> > > Chuck > > > _______________________________________________ > NumPy-Discussion mailing list > NumPy-Discussion@scipy.org > http://mail.scipy.org/mailman/listinfo/numpy-discussion > >
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion