SLICE Function

Standard Library function that subsets an array along one of its dimensions.

enabled.

Usage

result = SLICE(array, dimension, indices)

Input Parameters

array—An array.

dimensionAn integer (³0) designating the dimension to subset.

indicesA vector of indices into dimension dimension.

Returned Value

result—An array of slices perpendicular to dimension dimension.

Keywords

Remove—If set and nonzero, indices refer to elements in dimension dimension of array to remove. By default, indices refer to elements of array to extract and return.

Discussion

In the case of a multidimensional input array, the dimension numbers refer to:

0—rows

1—columns

2—planes of the row x column arrays

3—blocks of the planes of the row x column arrays

Examples

Example 1

a = INDGEN(6, 5, 2)
PM, a, ['',''], SLICE(a, 0, [1,3,5])

Output

0       6      12      18      24
1       7      13      19      25
2       8      14      20      26
3       9      15      21      27
4      10      16      22      28
5      11      17      23      29
30      36      42      48      54
31      37      43      49      55
32      38      44      50      56
33      39      45      51      57
34      40      46      52      58
35      41      47      53      59
1       7      13      19      25
3       9      15      21      27
5      11      17      23      29
31      37      43      49      55
33      39      45      51      57
35      41      47      53      59

Example 2

a = INDGEN(3,5)
b= SLICE(a, 1, [1,3])
c= SLICE(a, 1, [1,3], /Remove)
PM, a
PM, b
PM, c

Output

0       3       6       9      12
1       4       7      10      13
2       5       8      11      14
3       9
4      10
5      11
0       6      12
1       7      13
2       8      14

Example 3

a = INDGEN(2,2,5)
b = SLICE(a, 2, [1,3])
c = SLICE(a, 2, [1,3], /Remove)
PM, a
PM, b
PM, c

Output

0       2
1       3
4       6
5       7
8      10
9      11
12      14
13      15
16      18
17      19
4       6
5       7
12      14
13      15
0       2
1       3
8      10
9      11
16      18
17      19