# Vocabulary/idot

 i. y Integers

Rank 1 -- operates on lists of y, producing a result of variable shape for each one -- WHY IS THIS IMPORTANT?

Returns an ascending (or descending) sequence of integers, wrapped to the shape specified by (|y).

```   i. 6
0 1 2 3 4 5
i. 2 3
0 1 2
3 4 5
i. 6 1
0
1
2
3
4
5
```

If an atom of y is negated, this specifies reversal along that dimension.

```   i. _6
5 4 3 2 1 0
i. 2 _3
2 1 0
5 4 3
i. _2 3
3 4 5
0 1 2
i. _2 _3
5 4 3
2 1 0
```

If y is all-positive, then y is the shape of the table (i.y).

That is, if shape is any given positive integer list, then (i.shape) is the same as: shape \$ i. (*/shape)

```   shape=: 2 3
i.shape
0 1 2
3 4 5

shape \$ i. (*/shape)
0 1 2
3 4 5
```

### Common uses

0. A video has been made showing common uses of the Integers monadic verb

1. Make a sample numeric matrix for miscellaneous test purposes

```   ] z=: i. 3 5
0  1  2  3  4
5  6  7  8  9
10 11 12 13 14
+/ z
15 18 21 24 27
+/"1 z
10 35 60
```

2. Generate the identity permutation

e.g. see the samples in Anagram Index (A.)

```   N=: 4
] i=: i.N    NB. the identity permutation on N points
0 1 2 3
```

3. Make a "self-indexing" numeric matrix for investigating the behavior of a given J primitive, e.g. Transpose (|:).

"self-indexing" here means that each atom represents its own array index

```   ii=: ] {. [: i. 10 #~ #    NB. utility verb for generating a test matrix

] z=: ii 2 3 4
0   1   2   3
10  11  12  13
20  21  22  23

100 101 102 103
110 111 112 113
120 121 122 123
```

### Use These Combinations

Combinations using i. y that have exceptionally good performance are shown in Miscellaneous Functions.

 x i. y Index Of

Rank Infinity -- operates on x and y as a whole, by items of x -- WHY IS THIS IMPORTANT?

Finds the first occurrence of y in x

```   'abracadabra' i. 'a'
0
'abracadabra' i. 'acd'   NB. several search terms at once
0 4 6

7 < 2^i.5
0 0 0 1 1                   NB. 1, 2 and 4 are smaller than 7
(7 < 2^i.5) i. 1
3                           NB. inequality satisfied starting with list element no 3
7 (< i. 1:) 2^i.5
3
```

If list x doesn't contain y, then (i.) returns (#x)

If you subsequently use this value to index x then J signals  index error

```   'abcdef' i. 'k'
6
6 { 'abcdef'
|index error
```

Use (i.) with a table x (i.e. a list of lists) to find the first row of x that matches y

This is a special case of internal rank

```   ] x=: > 'alpha' ; 'bravo' ; 'charlie'
alpha
bravo
charlie

x i. 'charlie'
2
```

y must match the entire row of x (including any trailing fill letters) for (i.) to find it. Otherwise (i.) returns (#x) (signifying "not found"), concealing your error.

So be sure to get the search term y right!

```   #x
3
3
\$x               NB. shape of table (width is seven chars)
3 7
x i. 'bravo  '   NB. y needs to be the full width of x (including the two trailing blanks)
1
```

### Related Primitives

Index Of Last (x i: y)

1. x i. y is a member of the i.-family.

2. The internal rank of x i. y uses items whose rank is the rank of items of x.

3. If rix is the rank of an item of x, the shape of the result is  (-rix)}.\$y

4. If x and y are of different classes, or if their items couldn't possibly match because of differing shapes, no error is signaled: each search simply fails to match.

5. To find all occurrences of y in x, not just the first, use Equal (=) or Match (-:) , together with Indices (I.) to convert the resulting Boolean list into indices.

```   'abracadabra' = 'a'
1 0 0 1 0 1 0 1 0 0 1
0 3 5 7 10