<jupyter_start><jupyter_text>Compare Computation Times in NumPy and Standard Python ListsNow that we know how to use numpy, let us see code and witness the key advantages of numpy i.e. convenience and speed of computation. In the data science landscape, you'll often work with extremely large datasets, and thus it is important point for you to understand how much computation time (and memory) you can save using numpy, compared to standard python lists.   Let's compare the computation times of arrays and lists for a simple task of calculating the element-wise product of numbers.<jupyter_code>import time
import numpy as np
## Comparing time taken for computation
list_1 = [i for i in range(1000000)]
list_2 = [j**2 for j in range(1000000)]

t0 = time.time()
product_list = list(map(lambda x, y: x*y, list_1, list_2))
t1 = time.time()
list_time = t1 - t0
print (t1-t0)

# numpy array 
array_1 = np.array(list_1)
array_2 = np.array(list_2)

t0 = time.time()
product_numpy = array_1 * array_2
t1 = time.time()
numpy_time = t1 - t0
print (t1-t0)

print("The ratio of time taken is {}".format(list_time//numpy_time))<jupyter_output>0.1472640037536621
0.005246877670288086
The ratio of time taken is 28.0
{'fraction_non_alphanumeric': 0.08063175394846218, 'fraction_numerical': 0.06317539484621779, 'mean_word_length': 4.788461538461538, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '361667', 'license': 'MIT', 'n_tokens_mistral': 421, 'n_tokens_neox': 385, 'n_words': 162, 'path': 'Course_1-PreLaunch_Preparatory_Content/Module_2-Python_Libraries/1-NumPy/Session6_Computation_Times_in_NumPy_vs_Python_Lists.ipynb', 'repo_name': 'Mathews-Tom/MSc_in_Machine_Learning_and_Artificial_Intelligence', 'size': '1203'}