views:

85

answers:

4

Is there a data type that simply holds a 2D grid of doubles?

Preferably in the JDK but I'm happy to use an open source 3rd party library like apache commons etc.

I'm looking for a class, and/or complimentary helper classes, that allow methods like these:

Grid g = new DoubleGrid(100, 100);

double min = g.getMinValue();
double someCell = g.getValueAt(x, y);
double origin = g.getValueAt(Coordinate.ORIGIN);

Ideally, more complicated things like:

Grid newGrid = GridTransformer.transform(g, new CellValueSquarer());

I'm completely making these classes up, and I don't need those particular methods per se, It's just an example of the sort of thing I'm looking for...

+1  A: 

You can try EJML or just google 'java matrix library'

pablochan
+3  A: 

Why don't you use a simple 2-dimensional array?

double[][] pixels = new double[100][100];
double mine = pixels[12][65];

Wrap it in some simple class as desired.

But there may be existing implementations somewhere...

Daniel Bleisteiner
I was a bit vague with "Nice java object" but basically, I _could_ write my own but I was looking for something off-the-shelf since it is more likely to be faster and full-featured than anything I write...
mattburns
What about double min = pixels.getMinValue(); ?mattburns question was quite precise and had a concrete use case.
tkr
A: 

Have you tried javax.vecmath

Andrew
A: 

You might want to try JAMA, which is a linear algebra package (and thus contains a matrix which is a 2D grid of doubles), or Apache Commons Math, which contains lots of mathematically useful stuff, including linear algebra. EJML, which @pablochan mentioned, is another reasonable choice.

Rex Kerr