[Numpy-discussion] Warning or error on conversion from complex to float.
Michael McNeil Forbes
Thu Nov 8 12:32:42 CST 2007
Is it possible or easy to add a warning and/or error when array
assignments are made that lose information? I just got caught with
the following type of code:
x = numpy.empty((2,),dtype=float)
x[:] = f()
I am pre-allocating arrays for speed, but made a change to f()
resulting in complex results. My code now silently ignores the
imaginary part. It would have been very helpful if the assignment
check to make sure that the conversion was not going to lose
information (presumably with an assert so that performance is not
affected outside of debugging).
Any simple suggestions on how to avoid this problem in the future?
How hard would it be to add such a check in numpy?
More information about the Numpy-discussion