<jupyter_start><jupyter_text>Numpy Exercise 2  Imports<jupyter_code>import numpy as np
%matplotlib inline
import matplotlib.pyplot as plt
import seaborn as sns
import antipackage
import github.ellisonbg.misc.vizarray as va<jupyter_output>Downloading:  https://raw.githubusercontent.com/ellisonbg/misc/master/vizarray.py
Using existing version:  github.ellisonbg.misc.vizarray<jupyter_text>Factorial Write a function that computes the factorial of small numbers using `np.arange` and `np.cumprod`.<jupyter_code>def np_fact(n):
    if n == 0:
        return 1
    elif n == 1:
        return 1
    else:
        a = np.arange(1,n+1,1)
        b = a.cumprod()
    return b[-1]
assert np_fact(0)==1
assert np_fact(1)==1
assert np_fact(10)==3628800
assert [np_fact(i) for i in range(0,11)]==[1,1,2,6,24,120,720,5040,40320,362880,3628800]<jupyter_output><empty_output><jupyter_text>Write a function that computes the factorial of small numbers using a Python loop.<jupyter_code>def loop_fact(n):
    if n == 0:
        return 1
    elif n == 1:
        return 1
    else:
        a = 1
        while n >= 1:
            a = n * a
            n = n - 1
        return a
assert loop_fact(0)==1
assert loop_fact(1)==1
assert loop_fact(10)==3628800
assert [loop_fact(i) for i in range(0,11)]==[1,1,2,6,24,120,720,5040,40320,362880,3628800]<jupyter_output><empty_output><jupyter_text>Use the `%timeit` magic to time both versions of this function for an argument of `50`. The syntax for `%timeit` is:```python%timeit -n1 -r1 function_to_time()```<jupyter_code># YOUR CODE HERE
%timeit -n1 -r1 (loop_fact)

%timeit -n1 -r1 (np_fact)<jupyter_output>1 loops, best of 1: 3.1 µs per loop
1 loops, best of 1: 2.86 µs per loop
{'fraction_non_alphanumeric': 0.11943793911007025, 'fraction_numerical': 0.0778688524590164, 'mean_word_length': 3.939306358381503, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 16, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '24550', 'license': 'MIT', 'n_tokens_mistral': 733, 'n_tokens_neox': 650, 'n_words': 173, 'path': 'assignments/assignment03/NumpyEx02.ipynb', 'repo_name': 'AaronCWong/phys202-2015-work', 'size': '1708'}