-1

I need a data structure in python similar to a matrix with fast access to nearby cells but with floating point indices.The Data size(number of points) is pretty large so I cannot scale the data to make it integral.

Note: The data is 3-dimentional coordinates ex: -3.4561 5.5985 0.3249

This is one cell.Similarly there are other cells. Each cell has an integral value inside it with range 0-100. I don't need full precision,two digits after decimal point are sufficient.

shash
  • 1
  • 1
  • 1
    Floating point indices in general makes no sense. How does your data look like, and how do you need to query it? – Hannes Ovrén Jan 07 '14 at 10:38
  • 1
    it seems weird to have floats as indices. Can you show some code to clarify what you mean? – Enermis Jan 07 '14 at 10:39
  • 2
    I remember python integers have no limited precision, see: http://stackoverflow.com/questions/9860588/maximum-value-for-long-integer – zhangxaochen Jan 07 '14 at 10:41
  • 3
    Sounds like you something like a kd-tree, not a matrix. – Fred Foo Jan 07 '14 at 10:53
  • Is what you need, interpolation between nearby cells? – M4rtini Jan 07 '14 at 10:56
  • 2
    This makes no sense at all. Multiple your indices by 100, and round. End of story. – David Heffernan Jan 07 '14 at 10:58
  • Not interpolation, what I need is ability to access any cell individually through the indices and get the value inside it. – shash Jan 07 '14 at 11:02
  • I can't round of the indices. I wrote coordinates to make clear that I don't want to make changes to the indices. – shash Jan 07 '14 at 11:07
  • Isn't this called a function of three parameters ? – val Jan 07 '14 at 11:08
  • multiply by 100 and rounding should be more than good enough, since you say yourself you don't need more than 2 decimals in precision. You could subclass and modify the getitem and setitem method to do this for you if you please. – M4rtini Jan 07 '14 at 11:12
  • Multiplying and rounding off solves the problem but I need to use the coordinates as they are. If the coordinates are: 2.3645,3.6384,1.7643 then I should be able to access through 2.36,3,63,1.76. The other parts of the program require this. – shash Jan 07 '14 at 11:33
  • 1
    why not store it in a data structure eg tuple (x, y, z, val). I assume you later want to plot or do some kind of visualization with it. in that case you can write functions that gets the value "closest" to a given s dimensional point. In essence your data to be "samples" within a space. treat it like that. Pandas might give you good tools to deal with it. – Joop Jan 07 '14 at 11:49
  • 1
    Can you write some pseudo code showing exactly what you're trying to do? – Eric Jan 07 '14 at 11:52

1 Answers1

1

"two digits after decimal point are sufficient"

Multiply the floats by 100 and truncate. Now they are integers and it works as expected.

If your data is sparse consider using a dictionary instead of a matrix with the coordinates(ints) as a tuple.

Sorin
  • 11,863
  • 22
  • 26