<jupyter_start><jupyter_text>NUmpy rewrite of calculate_distance function<jupyter_code>import math
def calculate_distance(coord1, coord2, box_length=None):
    """
    Calculate the distance between two 3D coordinates.
    Parameters
    ----------
    coord1, coord2: list
        The atomic coordinates
    box_length : float
        The box length. If given, the minimum image convention will be used to calculate the distance.
    Returns
    -------
    distance: float
        The distance between the two points.
    """
    distance = 0
    for i in range(3):
        dim_dist = (coord1[i] - coord2[i])
        if box_length:
            coord_dist = dim_dist - box_length * np.round(dim_dist / box_length)
        dim_dist = dim_dist**2
        distance += dim_dist
    distance = np.sqrt(distance)
    return distance

import numpy as np

point1 = np.array([0,0,0])

point2 = np.array([0,8,0])


calculate_distance(point1, point2)
dimensional_distance = point2 - point1

print(dimensional_distance)


dimensional_distance = point1 - point2
print(dimensional_distance)

dd2 = dimensional_distance ** 2 

dd2_sum = dd2.sum()

distance = math.sqrt(dd2_sum)

print(distance)


import math
def calculate_distance_np(coord1, coord2, box_length=None):
    """
    Calculate the distance between two 3D coordinates.
    Parameters
    ----------
    coord1, coord2: np.array
        The atomic coordinates
    box_length : float
        The box length. If given, the minimum image convention will be used to calculate the distance.
    Returns
    -------
    distance: float
        The distance between the two points.
    """
    
    coord_dist = coord1 - coord2
    
    
    if box_length:
            coord_dist = coord_dist - box_length * np.round(coord_dist / box_length)
    
   

#how many axis it has 

    if coord_dist.ndim < 2:
        coord_dist = coord_dist.reshape(1,-1)





    coord_dist = coord_dist ** 2
    
    coord_dist_sum = coord_dist.sum(axis=1)
    
    distance = np.sqrt(coord_dist_sum)
    
    return distance

    
    

## Check your funtction w/assert statements


point_1 = np.array([0,0,0])

point_2 = np.array([1,0,0])

dist1 = calculate_distance_np(point_1, point_2)


assert dist1 == 1

point_1 = np.array([0,0,0])

point_2 = np.array([0,1,1])




dist2 = calculate_distance_np(point_1, point_2)

assert dist2 == math.sqrt(2)
coord_set1 = np.array([[0,0,0], [0, 1, 0]])

coord_set2 = np.array([[0, 8, 0], [0, 1.5, 0]])
calculate_distance_np(coord_set1, coord_set2, 10)
coord_set1.ndim<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10707307542008597, 'fraction_numerical': 0.03399765533411489, 'mean_word_length': 2.8323353293413174, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 5, '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': '577600', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 880, 'n_tokens_neox': 846, 'n_words': 218, 'path': 'day4.ipynb', 'repo_name': 'msse-2021-bootcamp/team1-project', 'size': '2559'}