<jupyter_start><jupyter_text>NumPy NumPy is a powerful linear algebra library for Python. What makes it so important is that almost all of the libraries in the PyData ecosystem (pandas, scipy, scikit-learn, etc.) rely on NumPy as one of their main building blocks. Plus we will use it to generate data for our analysis examples later on!<jupyter_code>import numpy as np
nourdine = [1,2,3]
nourdine
np.array(nourdine)
my_matrix = [
    [1,2,3],
    [4,5,6],
    [7,8,9]
]
my_matrix
np.array(my_matrix)<jupyter_output><empty_output><jupyter_text>Built-in MethodsThere are lots of built-in ways to generate arrays.  arangeReturn evenly spaced values within a given interval.<jupyter_code>np.arange(1,25)
np.arange(0,11,1.5)<jupyter_output><empty_output><jupyter_text>zeros and onesGenerate arrays of zeros or ones.<jupyter_code>np.zeros(3)
np.ones(20)
np.zeros((3,5))
np.ones((3,7))<jupyter_output><empty_output><jupyter_text>linspace Return evenly spaced numbers over a specified interval.<jupyter_code>np.linspace(0,4,20)
np.eye(4)
np.linspace(0,10,2) * np.eye(2)<jupyter_output><empty_output><jupyter_text>Random Numpy also has lots of ways to create random number arrays:<jupyter_code>np.random.rand(4)
np.random.randn(5,4)
np.random.seed(555)
np.random.rand(4)
np.random.randint(1,3100)
np.random.randint(1,100,50)
np.random.seed(44)
np.random.rand(4)
np.random.seed(44)
np.random.rand(4)<jupyter_output><empty_output><jupyter_text>Array Attributes and MethodsLet's discuss some useful attributes and methods for an array:<jupyter_code>array = np.arange(25)
ra = np.random.randint(0,50,10)
array
ra.dtype
array.reshape(25,1)
ra.max()
ra
ra.argmax()
ra.min()
ra.max()
ra.mean()
ra.argmin()
ra.shape
array.shape
array.reshape(5,5)
array.shape<jupyter_output><empty_output><jupyter_text>dtypeYou can also grab the data type of the object in the array:<jupyter_code>arr = np.array(np.random.rand(4,40,50))
arr.shape
arr.dtype
arr<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1267245784363822, 'fraction_numerical': 0.0398569238630557, 'mean_word_length': 6.67843137254902, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, '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': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '383938', 'license': 'MIT', 'n_tokens_mistral': 794, 'n_tokens_neox': 765, 'n_words': 171, 'path': 'NumPy/00-NumPy-Arrays.ipynb', 'repo_name': 'mohamednourdine/PyTorch', 'size': '1957'}