[Numpy-discussion] asarray issue with type codes
Mon Jul 28 18:50:52 CDT 2008
I ran into a little problem in some type checking code for a C extension
I'm writing. I construct X as a C-long array and then I cast it to a C-int
array Y, however the type code does not change. However, when I try
constructing the array from scratch as a C-int, I get the right type code
I assumed that when X gets casted to a C-int, no copying should occur but
a new array view should be constructed with the C-int type code. What's
wrong with this logic?
Also note that casting from a C-long (type code 7) to a double to a C-int
returns an array with the right type code, although a double copy occurs.
# Construct X as a C-long.
In : X=numpy.zeros((10,10),dtype='l')
# Now cast X to a C-int.
In : Y=numpy.asarray(X, dtype='i')
# Check X and Y's data type; they are the same.
In : X.dtype
In : Y.dtype
# Their type codes are the same.
In : X.dtype.num
In : Y.dtype.num
# Constructing with dtype='i', gives the right type code.
In : Z=numpy.zeros((10,10),dtype='i')
In : Z.dtype
In : Z.dtype.num
More information about the Numpy-discussion