# find_neighbor_pores¶

CubicDual.find_neighbor_pores(pores, mode='union', flatten=True, include_input=False)

Returns a list of pores that are direct neighbors to the given pore(s)

Parameters
• pores (array_like) – Indices of the pores whose neighbors are sought

• flatten (bool) – If `True` (default) the returned result is a compressed array of all neighbors. If `False`, a list of lists with each sub-list containing the neighbors for each input site. Note that an unflattened list might be slow to generate since it is a Python `list` rather than a Numpy `array`.

• include_input (bool) – If `False` (default) then the input pores are not included in the returned list(s). Note that since pores are not neighbors of themselves, the neighbors of pore N will not include N, even if this flag is `True`.

• mode (str) –

Specifies logic to filter the resulting list. Options are:

’or’ : (default) All neighbors of the input pores. This is also known as the ‘union’ in set theory or ‘any’ in boolean logic. Both keywords are accepted and treated as ‘or’. ‘xor’ : Only neighbors of one and only one input pore. This is useful for counting the pores that are not shared by any of the input pores. This is known as ‘exclusive_or’ in set theory, and is an accepted input. ‘xnor’ : Neighbors that are shared by two or more input pores. This is equivalent to counting all neighbors with ‘or’, minus those found with ‘xor’, and is useful for finding neighbors that the inputs have in common. ‘and’ : Only neighbors shared by all input pores. This is also known as ‘intersection’ in set theory and (somtimes) as ‘all’ in boolean logic. Both keywords are accepted and treated as ‘and’.

Returns

• If `flatten` is `True`, returns a 1D array of pore indices

• filtered according to the specified mode. If `flatten` is

• `False`, returns a list of lists, where each list contains the

• neighbors of the corresponding input pores.

Notes

The `logic` options are applied to neighboring pores only, thus it is not possible to obtain pores that are part of the global set but not neighbors. This is because (a) the list of global pores might be very large, and (b) it is not possible to return a list of neighbors for each input pores if global pores are considered.

Examples

```>>> import openpnm as op
>>> pn = op.network.Cubic(shape=[5, 5, 5])
>>> Ps = pn.find_neighbor_pores(pores=[0, 2])
>>> print(Ps)
[ 1  3  5  7 25 27]
>>> Ps = pn.find_neighbor_pores(pores=[0, 1])
>>> print(Ps)
[ 2  5  6 25 26]
>>> Ps = pn.find_neighbor_pores(pores=[0, 1], mode='union',
...                             include_input=True)
>>> print(Ps)
[ 0  1  2  5  6 25 26]
>>> Ps = pn.find_neighbor_pores(pores=[0, 2], flatten=False)
>>> print(Ps[0])
[ 1  5 25]
>>> print(Ps[1])
[ 1  3  7 27]
>>> Ps = pn.find_neighbor_pores(pores=[0, 2], mode='xnor')
>>> print(Ps)
[1]
>>> Ps = pn.find_neighbor_pores(pores=[0, 2], mode='xor')
>>> print(Ps)
[ 3  5  7 25 27]
```