<jupyter_start><jupyter_text>Introduction to NumPy Arrays<jupyter_code>import numpy as np
import math<jupyter_output><empty_output><jupyter_text>Review of List Behavior<jupyter_code># construct some coordinates
coordinates = [[0,0,0], [0,0,math.pow(2,1/6)],[0,0,2*math.pow(2,1/6)],[math.pow(2,1/6),0,0]]

second_coordinate = coordinates[1]

print(second_coordinate)
translation_vector = [0.1,-0.1,0]

print(second_coordinate)
print(translation_vector)

# write some code for translating second coordinate by translation vector

new = []
for a in range(len(second_coordinate)):
    new.append(second_coordinate[a]+translation_vector[a])

print(new)<jupyter_output><empty_output><jupyter_text>$$ (x_1 + x_2, y_1 + y_2, z_1 + z_2) $$<jupyter_code># create numpy array from list
second_coordinate_np = np.array(second_coordinate)

# create numpy array from a list
translation_vector_np = np.array(translation_vector)
print(type(second_coordinate))
print(type(second_coordinate_np))
second_coordinate_np
new_coordinate_np = second_coordinate_np + translation_vector_np

print(new_coordinate_np)
# This is very different from the behavior of python lists.
second_coordinate + translation_vector
a1 = np.array([2,1,0])
a2 = np.array([1,3,5])

print(a1*a2)
print(a1+a2)
a1 = [2,1,0]
a2 = [1,3,5]

print(a1+a2)

#This will result in a TypeError
#print(a1*a2)<jupyter_output><empty_output><jupyter_text>Array Shape<jupyter_code>my_array = np.array([0.2,0.3])

second_coordinate_np + my_array
second_coordinate_np.shape
coordinates_np = np.array(coordinates)
print(coordinates)
coordinates_np.shape
## Accessing information in nested list
atom_index_3 = coordinates[3]
x_coord_atom_3 = atom_index_3[0]
print(x_coord_atom_3)
coordinates[3][0]
coordinates_np[3, 0:2]<jupyter_output><empty_output><jupyter_text>Broadcasting<jupyter_code>print(coordinates)
print(translation_vector)
# Translate all coordinates by translation vector using lists and python standard library

num_atoms = len(coordinates)

new_coordinates = []

for n in range(num_atoms):
    
    atom_coord = coordinates[n]
    updated_coord = []
    for i in range(3):
        translate_coordinate = atom_coord[i] + translation_vector[i]
        updated_coord.append(translate_coordinate)
        
    new_coordinates.append(updated_coord)
    
print(new_coordinates)
new_coordinates_np = coordinates_np + translation_vector_np
print(new_coordinates_np)
10 * coordinates_np
new_coordinates_np > 0
new_coordinates_np[new_coordinates_np > 0]<jupyter_output><empty_output><jupyter_text>Array Axes<jupyter_code># calculate mean of all values in array
coordinates_np.mean()
coordinates_np.shape
print(coordinates_np.mean(axis=0))
print(coordinates_np.mean(axis=1))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10944910616563298, 'fraction_numerical': 0.028091937249179133, 'mean_word_length': 7.704761904761905, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 27, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '202817', 'license': 'MIT', 'n_tokens_mistral': 1013, 'n_tokens_neox': 982, 'n_words': 178, 'path': 'numpy_lesson.ipynb', 'repo_name': 'tpeir001/numpy-lesson', 'size': '2741'}