<jupyter_start><jupyter_text>Numpy Crash Course<jupyter_code>import numpy as np<jupyter_output><empty_output><jupyter_text>Numpy Arrays  List to array<jupyter_code>l = [1, 2, 3]
type(l)
np.array(l)
arr = np.array(l)
arr.shape<jupyter_output><empty_output><jupyter_text>Nested list to Matrix<jupyter_code>nestedlist = [[1,2,3],[4,5,6],[7,8,9]]
matrix = np.array(nestedlist)
matrix
matrix.shape<jupyter_output><empty_output><jupyter_text>Numpy Range<jupyter_code>np.arange(0,10)
np.arange(0,10,2)<jupyter_output><empty_output><jupyter_text>Zeros<jupyter_code>np.zeros(5)
np.zeros((5,5))<jupyter_output><empty_output><jupyter_text>Ones<jupyter_code>np.ones(5)
np.ones((3,3))<jupyter_output><empty_output><jupyter_text>Linspace<jupyter_code>np.linspace(0,10,4)
np.linspace(0,10,20)<jupyter_output><empty_output><jupyter_text>Identity Matrix<jupyter_code>np.eye(3)<jupyter_output><empty_output><jupyter_text>Random   Uniform Distribution<jupyter_code>np.random.rand(1)
np.random.rand(5)
np.random.rand(3,3)<jupyter_output><empty_output><jupyter_text>Starndard Normal Distribution (mean = 0, sd = 1)<jupyter_code>np.random.randn(5)
np.random.randn(3,3)<jupyter_output><empty_output><jupyter_text>Normal Distribution<jupyter_code>np.random.normal(10,1) # mean =10, sd =1<jupyter_output><empty_output><jupyter_text>Random Integer<jupyter_code>np.random.randint(0,100) # low inclusive, high exclusive
np.random.randint(0,100,10)<jupyter_output><empty_output><jupyter_text>Seed<jupyter_code>np.random.seed(42)
np.random.rand(4)<jupyter_output><empty_output><jupyter_text>Array Attributes and Methods<jupyter_code>arr = np.arange(25)
arr
ranarr = np.random.randint(0,50,10)
ranarr<jupyter_output><empty_output><jupyter_text>Reshape<jupyter_code>arr.reshape(5,5)
arr.reshape(5,3) # new shape should fit the data<jupyter_output><empty_output><jupyter_text>Maximum and Minimum<jupyter_code># maximum 
ranarr.max()
# minimum
ranarr.min()
# index of max
ranarr.argmax()
# index of min
ranarr.argmin()<jupyter_output><empty_output><jupyter_text>Array datatype<jupyter_code>ranarr.dtype<jupyter_output><empty_output><jupyter_text>Index Selection<jupyter_code>arr = np.arange(0,11)
arr
arr[3]
arr[2:4]
arr[:5]
arr[5:]<jupyter_output><empty_output><jupyter_text>BroadCasting<jupyter_code>arr = np.arange(0,10)
arr
# broadcasting operation on all elements
arr ** 2
arr
# slice_arr holds the orignal array (shallow copy)
arr_slice = arr[:5]
arr_slice
arr_slice[1] = 10
arr_slice
arr
# deep copy
arr_copy = arr.copy()
arr_copy
arr_copy[1] = 100
arr_copy
arr<jupyter_output><empty_output><jupyter_text>Indexing on 2D array<jupyter_code>matrix = np.arange(1,10).reshape(3,3)*5
matrix
matrix[1]
matrix[1][1]
matrix[1,1]
matrix[:2,1:]<jupyter_output><empty_output><jupyter_text>Conditional Selection<jupyter_code>arr = np.arange(1,11)
arr
arr > 4
arr[arr > 4]<jupyter_output><empty_output><jupyter_text>Numpy Array Operations<jupyter_code>arr = np.arange(0,11)
arr
arr+4
arr ** 2
arr/arr
np.sqrt(arr)
np.log(arr)
arr.sum()
arr.mean()
matrix = np.arange(1,13).reshape(3,4)
matrix.sum()
matrix.sum(axis=0) # sum on vertical axis (accross the rows)
matrix.sum(axis=1) # sum on horizontal axis (acrsso the columns)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1465919701213819, 'fraction_numerical': 0.03890445066915655, 'mean_word_length': 10.903703703703703, 'pattern_counts': {'":': 0, '<': 89, '<?xml version=': 0, '>': 91, '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': '22', 'dir': 'jupyter-structured-clean-dedup', 'id': '666305', 'license': 'MIT', 'n_tokens_mistral': 1429, 'n_tokens_neox': 1380, 'n_words': 172, 'path': 'Numpy Crash Course.ipynb', 'repo_name': 'Chirag-Juneja/numpy', 'size': '3213'}