def count_neighbors(coordinates_a, coordinates_b, periodic, r):
    '''Count the neighbours number of neighbors.

    :param np.ndarray coordinates_a: Either an array of coordinates of shape (N,3)
                                     or a single point of shape (3,)
    :param np.ndarray coordinates_b: Same as coordinates_a
    :param np.ndarray periodic: Either a matrix of box vectors (3, 3) or an
                                array of box lengths of shape (3,). Only
                                orthogonal boxes are supported.
    :param float r: Radius of neighbor search

    '''
    indices = nearest_neighbors(coordinates_a, coordinates_b, periodic, r=r)[0]

    if len(indices) == 0:
        return 0

    if isinstance(indices[0], collections.Iterable):
        return [len(ix) for ix in indices]
    else:
        return len(indices)
Count the neighbours number of neighbors.

    :param np.ndarray coordinates_a: Either an array of coordinates of shape (N,3)
                                     or a single point of shape (3,)
    :param np.ndarray coordinates_b: Same as coordinates_a
    :param np.ndarray periodic: Either a matrix of box vectors (3, 3) or an
                                array of box lengths of shape (3,). Only
                                orthogonal boxes are supported.
    :param float r: Radius of neighbor search