[Numpy-discussion] Assigning complex values to a real array

Stéfan van der Walt stefan@sun.ac...
Sat Mar 7 03:30:03 CST 2009


2009/3/7 Charles R Harris <charlesr.harris@gmail.com>:
>> a = np.zeros(6) # real
>> b= np.arange(6)*(2+3j) # complex
>> a[1] = b[1] # shouldn't this break?
>>
>> What is the rationale behind this behaviour?
>
> The same as this:
>
> In [1]: a = zeros(2)
>
> In [2]: a[0] = '1'
>
> In [3]: a
> Out[3]: 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.

Cheers
Stéfan


More information about the Numpy-discussion mailing list