<jupyter_start><jupyter_text>NumPy rewrite of the -calculate_distance- function<jupyter_code>import math
def calculate_distance(coord1, coord2, box_length=None):
    """
    Calculate the distance between two points. When box_length is set, the minimum image convention is used to calculate the distance between the points.

    Parameters
    ----------
    coord1, coord2 : list
        The coordinates of the points, [x, y, z]
    
    box_length : float, optional
        The box length

    Returns
    -------
    distance : float
        The distance between the two points accounting for periodic boundaries
    """
    distance = 0
        
    for i in range(3):
        hold_dist = abs(coord2[i] - coord1[i])
    
        if (box_length):    
            if hold_dist > box_length/2:
                hold_dist = hold_dist - (box_length * round(hold_dist/box_length))
        distance += math.pow(hold_dist, 2)

    return math.sqrt(distance)

import numpy as np
pt1 = np.array([0,0,0])
pt2 = np.array([0,8,0])

calculate_distance(pt1,pt2)
dimensional_distance = pt2-pt1
print (dimensional_distance)
dd2 = dimensional_distance **2
dd2_sum=dd2.sum()
distance = math.sqrt(dd2_sum)
print (distance)
def calculate_distance_np(coord1, coord2, box_length=None):
    """
    Calculate the distance between two points. When box_length is set, the minimum image convention is used to calculate the distance between the points.

    Parameters
    ----------
    coord1, coord2 : np.array
        The coordinates of the points, [x, y, z]
    
    box_length : float, optional
        The box length

    Returns
    -------
    distance : float
        The distance between the two points accounting for periodic boundaries
    """
    coord_dist=coord1-coord2
    if box_length:    
            coord_dist = coord_dist - (box_length * np.round(coord_dist/box_length))
    if coord_dist.ndim <2:
        #reshaping the array, make it have 2 dimensions
        coord_dist = coord_dist.reshape (1,-1)
    coord_dist=coord_dist**2
    dist_sum= coord_dist.sum(axis=1)
    distance = np.sqrt(dist_sum)
    return distance

dist1 = calculate_distance(pt1,pt2,2.5)
dist2 = calculate_distance_np(pt1,pt2,2.5)

assert dist1 == dist2

pts1= [[0,0,0],[0,0,1],[0,0,2]]
pts2= [[8,0,0],[8,0,1],[8,0,2]]

pt1np = np.array(pts1)
pt2np = np.array(pts2)

calculate_distance_np(pt1np,pt2np,3.3)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10972568578553615, 'fraction_numerical': 0.03283458021612635, 'mean_word_length': 2.9719471947194718, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '319179', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 795, 'n_tokens_neox': 777, 'n_words': 211, 'path': 'day4.ipynb', 'repo_name': 'msse-2021-bootcamp/team2-project', 'size': '2406'}