Better use a tuple or numpy array for storing coordinates

Posted by Ivan on Stack Overflow See other posts from Stack Overflow or by Ivan
Published on 2010-04-01T21:17:57Z Indexed on 2010/04/01 21:23 UTC
Read the original article Hit count: 236

Filed under:
|
|
|
|

Hi,

I'm porting an C++ scientific application to python, and as I'm new to python, some problems come to my mind:

1) I'm defining a class that will contain the coordinates (x,y). These values will be accessed several times, but they only will be read after the class instantiation. Is it better to use an tuple or an numpy array, both in memory and access time wise?

2) In some cases, these coordinates will be used to build a complex number, evaluated on a complex function, and the real part of this function will be used. Assuming that there is no way to separate real and complex parts of this function, and the real part will have to be used on the end, maybe is better to use directly complex numbers to store (x,y)? How bad is the overhead with the transformation from complex to real in python? The code in c++ does a lot of these transformations, and this is a big slowdown in that code.

3) Also some coordinates transformations will have to be performed, and for the coordinates the x and y values will be accessed in separate, the transformation be done, and the result returned. The coordinate transformations are defined in the complex plane, so is still faster to use the components x and y directly than relying on the complex variables?

Thank you

© Stack Overflow or respective owner

Related posts about python

Related posts about numpy