[NumPy-Tickets] [NumPy] #1437: Copy a complex array into a slice of a real array takes the real part.
NumPy Trac
numpy-tickets@scipy....
Sun Mar 21 15:47:33 CDT 2010
#1437: Copy a complex array into a slice of a real array takes the real part.
---------------------------+------------------------------------------------
Reporter: SevenThunders | Owner: somebody
Type: defect | Status: new
Priority: normal | Milestone:
Component: Other | Version:
Keywords: |
---------------------------+------------------------------------------------
Numpy gives surprising results when copying complex data into a portion of
a predefined real data array. It takes the real part of the complex data,
and does not retype the real array to be complex.
Here is some example code:
{{{
import numpy as np
z = np.zeros((3,4))
u = np.random.randn(3,2) + 1j * np.random.randn(3,2)
z[:,1:3] = u
print(z)
}}}
One can contrast this behavior, with say Matlab, or with numpy itself
under different contexts, e.g. adding to the above code
{{{
u4 = np.random.randn(3,4) + 1j * np.random.randn(3,4)
z = u4
print(z)
}}}
Thus when the right hand side has the same size as the left, numpy will
promote the left hand side, z, to be complex.
I can only presume that the reason for this behavior is performance,
probably due to maintaining a complex array as interleaved real and
imaginary. If so, then for consistency and to catch the obvious sorts of
bugs this creates, it would be far preferable to throw an exception for
the complex to real copy for a sliced array.
After all it is pretty easy to get the default behavior by taking the real
part of the right hand side.
--
Ticket URL: <http://projects.scipy.org/numpy/ticket/1437>
NumPy <http://projects.scipy.org/numpy>
My example project
More information about the NumPy-Tickets
mailing list