def nearest(p0, p1, cutoff=None):
ind0, ind1 = [], []<EOL>for i in range(len(p0)):<EOL><INDENT>dist = np.sqrt(((p0[i] - p1)**<NUM_LIT:2>).sum(axis=-<NUM_LIT:1>))<EOL>if cutoff is None:<EOL><INDENT>ind1.append(dist.argmin())<EOL><DEDENT>elif dist.min() < cutoff:<EOL><INDENT>ind0.append(i)<EOL>ind1.append(dist.argmin())<EOL><DEDENT><DEDENT>if cutoff is None:<EOL><INDENT>return ind1<EOL><DEDENT>return ind0, ind1<EOL>
Correlate closest particles with each other (within cutoff).

Returns ind0, ind1 so that p0[ind0] is close to p1[ind1].

Parameters
----------
    p0, p1 : numpy.ndarray
        The particle positions.
    cutoff : Float or None, optional
        If not None, only returns particle indices with distance less
        than `cutoff`. Default is None.

Returns
-------
    ind0, ind1 : List
        The lists of particle indices, p0[ind0] is close to p1[ind1].