Order array by dimensions


#1

Hello. I’m having a problem with saving of multidimensional array to CSV file, or just fetch.
The array has X and Y dimensions, which are the coordinates, and Z values.
When I save it to CSV file or just fetch, the X values are not consecutive, for example I get
{ X, Y}
0, 1
0, 2
0, 3
1, 1
1, 2
0, 4
0, 5

But I need it to be
{X, Y}
0, 1
0, 2
0, 3
0, 4
0, 5
1, 2
1, 2

How can I make it? Sorting by X first and after by Y does not help, because after Y sorting, X is not sorted anymore.
Any help will be highly appreciated.


#2

You need to use sort()


#3

Is it possible to sort by 2 dimensions at the same time?


#4

Hi @igorch,

The trick is to first apply() the dimension values as attributes, then sort on the attributes. Something like this:

AFL% show(FOO);
{i} schema
{0} 'FOO<val:int64> [x=0:15:0:4; y=0:15:0:4]'
AFL% 
AFL% save(sort(project(apply(FOO, xx, x, yy, y),
CON>                   xx, yy, val)),
CON>      '/tmp/foo.csv', format:'csv');