[Numpy-discussion] I,J,K Coordinates from Cell ID
Andrea Gavana
andrea.gavana@gmail....
Thu Feb 28 14:47:20 CST 2008
Hi All,
I have some problems in figuring out a solution for an issue I am
trying to solve. I have a 3D grid of dimension Nx, Ny, Nz; for every
cell of this grid, I calculate the cell centroids (with the cell
coordinates x, y, and z) and then I try to find which cell centroid is
the closest to a specified point in 3D (which I supply). I still
haven't figured out how to do this, even if I have some ideas (and
suggestions for this problem are welcome :-D ). But the problem is
another one.
When I find the closest centroid, I know only the cell ID of this
centroid. The cell ID is (usually) defined as:
ID = (K-1)*Nx*Ny + (J-1)*Nx + I - 1
Where I, J, K are the cell indexes. Now, the problem is, how can I
calculate back the I, J, K indexes knowing only the cell ID? I am
trying to solve this using numpy (as my grid is stored using a numpy
array), but it's something akin to the Matlab function ind2sub...
Thank you for your suggestions.
Andrea.
"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.alice.it/infinity77/
More information about the Numpy-discussion
mailing list