num_neighbors

DelaunayVoronoiDual.num_neighbors(pores, mode='or', flatten=False)

Returns the number of neigbhoring pores for each given input pore

Parameters
  • pores (array_like) – Pores whose neighbors are to be counted

  • flatten (bool, optional) – If False (default) the number of pores neighboring each input pore as an array the same length as pores. If True the sum total number of is counted.

  • mode (str) –

    The logic to apply to the returned count of pores:

    ’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 False, a 1D array with number of neighbors in each

  • element, otherwise a scalar value of the number of neighbors.

Notes

This method literally just counts the number of elements in the array returned by find_neighbor_pores using the same logic. Explore those methods if uncertain about the meaning of the mode argument here.

Examples

>>> import openpnm as op
>>> pn = op.network.Cubic(shape=[5, 5, 5])
>>> Np = pn.num_neighbors(pores=[0, 1], flatten=False)
>>> print(Np)
[3 4]
>>> Np = pn.num_neighbors(pores=[0, 2], flatten=True)
>>> print(Np)
6
>>> Np = pn.num_neighbors(pores=[0, 2], mode='and', flatten=True)
>>> print(Np)
1