[Numpy-discussion] Assigning complex values to a real array
Sat Mar 7 03:35:35 CST 2009
On Sat, Mar 7, 2009 at 03:30, Stéfan van der Walt <email@example.com> wrote:
> 2009/3/7 Charles R Harris <firstname.lastname@example.org>:
>>> a = np.zeros(6) # real
>>> b= np.arange(6)*(2+3j) # complex
>>> a = b # shouldn't this break?
>>> What is the rationale behind this behaviour?
>> The same as this:
>> In : a = zeros(2)
>> In : a = '1'
>> In : a
>> Out: array([ 1., 0.])
> This difference is that, in your example, no information is lost.
> When assigning a complex value to a real array, you are probably doing
> something wrong.
In : z = zeros(3, int)
In : z = 1.5
In : z
Out: array([0, 1, 0])
"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
-- Umberto Eco
More information about the Numpy-discussion