 # Choose subsets into arrays

Say that I have an array `A` of dimensions `n1*n2*n3*n4`.

If you want to choose the first elements of dimension `n1`, `n2`, then `A[1,1,.,.];`

If you want to choose the first elements of dimension `n1`, `n3`, then `A[1,.,1,.];`

If you want to choose the first elements of dimension `n1`, `n2`, `n4` then `A[1,1,.,1];`

Or in general another element then `A[12,7,.,5];`

Or in general another element then `A[12,7,1547,5];`

and so on...

How can I make the indexes to be part of a function or global variables that allow me to choose either specific elements in a given dimension or all the elements in a dimension (dot)?

0

There are several ways that you can access elements of a multi-dimensional array in GAUSS. I'm not certain that I understand enough context about your program and how you think about the data to give you the answer that you are looking for.

However, if you will only want to select a single index or all elements of a particular index it may be helpful to know that when you specify an index as zero, it acts the same as `.` and selects all elements.

For example:

``````// Create an example array
X = areshape(seqa(1.1, 1, 24), 2|3|4);

print X;``````

will print the full array, `X`.

``````Plane [1,.,.]

1.1      2.1      3.1      4.1
5.1      6.1      7.1      8.1
9.1     10.1     11.1     12.1

Plane [2,.,.]

13.1     14.1     15.1     16.1
17.1     18.1     19.1     20.1
21.1     22.1     23.1     24.1``````

As you know you can access individual elements like this:

``````a = 2;
b = 1;
c = 3;

print X[a,b,c];``````
``15.1``

Setting an index equal to zero will select the entire range:

``````a = 2;
b = 1;
c = 0;

// Print the entire first row of the second hypercube
print X[a,b,c];``````
``````Plane [1,.,.]
13.1     14.1     15.1     16.1 ``````
``````a = 0;
b = 1;
c = 0;

// Print the entire first row of both hypercubes
print X[a,b,c];``````
``````Plane [1,.,.]
1.1      2.1      3.1      4.1

Plane [2,.,.]
13.1     14.1     15.1     16.1 ``````

Does that answer your question, or are you looking for something else? aptech

1,548

0

Thank you! That's exactly what I was looking, in your example, you did that:

 a = 0; b = 1; c = 0; // Print the entire first row of both hypercubes print X[a,b,c];

I didn't know that this is equivalent to print X[.,1,.]; ### Have a Specific Question?

Get a real answer from a real person

### Need Support?

Get help from our friendly experts.