[Numpy-discussion] can int and float exists in one array?(about difference in indexing Matlab matrix and Numpy array)
Travis Oliphant
oliphant at ee.byu.edu
Tue Nov 28 19:05:46 EST 2006
Zhang Sam wrote:
> Thanks for so many replies.
>
> In fact, I want to use several arrays to store the original data from
> a practical project. In every arrays, two or three column will be
> store the index. The main computation is still on matrices(float type)
> which is built from the original data. When building the main
> matrix, I need the repeated use of the index stored in the original
> data. So I hope both int and float can exist in one array with numpy,
> just for the original data.
I think you probably want to use a record-array here.
Matlab does not store both integers and floating point in the same
matrix. It stores integers *as* floating point in your float array.
Matlab just allows floating-point arrays to be used as indexes (because
for a long time there was only floating-point matrices in Matlab).
NumPy forces you to be explicit in using an integer array for indexing
into an array. You are mis-interpreting the situation with Matlab.
The accurate representation is that Matlab allows indexing with floating
point arrays. It would be possible to lift the restriction with NumPy,
but I suspect it's probably best to leave it the way it is so that users
are clear about how they want to convert from integers to floating-point.
-Travis
More information about the NumPy-Discussion
mailing list