grid_neighbors
grid_neighbors(gs, order=1, include_diagonals=False, include_self=False, output_unique=True)
Computes the n-th order neighbors of each cell in a grid.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
gs |
(dim,) numpy int array
|
grid size in each dimension |
required |
order |
neighborhood order (e.g., 1 means first-order neighbors) |
1
|
|
include_diagonals |
whether diagonal cells are considered to be neighbors |
False
|
|
include_self |
whether a cell is considered to be its own neighbor |
False
|
|
output_unique |
whether to output only unique neighbors (i.e., remove duplicates). This should only matter for order>=2 (for order=1, the output is always unique but this flag will change the ordering) |
True
|
Returns:
Name | Type | Description |
---|---|---|
N |
(num_neighbors, n) numpy int array
|
The i-th column contains the list of neighbors of the i-th cell. Negative entries denote out-of-bounds cells. |
Examples:
gs = np.array([90,85])
# This should be *only* the 8 neighbors at a distance of h
N = gpytoolbox.grid_neighbors(gs, include_diagonals=False, include_self=False,order=1)
# Now in each column of N, we have the indices of the four non-diagonal neighbors of the corresponding cell. For example, for the first (bottom left) cell, the neighbors are:
N[:,0]
# which should be two values of -1 (out of bounds), one value of 1 (the cell to the right), and one value of 85 (the cell above).
Source code in src/gpytoolbox/grid_neighbors.py
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
|