<jupyter_start><jupyter_text>NumPy Indexing<jupyter_code>import numpy as np
#reating sample array
arr = np.arange(0,11)
#Show
arr<jupyter_output><empty_output><jupyter_text>Bracket Indexing<jupyter_code>#get a value at an index
arr[8]
#Get values in a range
arr[1:5]
#Get values in a range
arr[0:5]<jupyter_output><empty_output><jupyter_text>Broadcasting<jupyter_code>#Setting a value with index range (Braodcasting)

arr[0:5]= 105

#Show
arr
#reset array, we'll see why I had to reset in a moment
arr = np.arange(0,11)
#Show
arr
slice_of_arr = arr[0:6]
slice_of_arr
#important notes on Slices

slice_of_arr[:]=100
#Show slice
slice_of_arr<jupyter_output><empty_output><jupyter_text>Now note the changes also occur in our original array!<jupyter_code>arr<jupyter_output><empty_output><jupyter_text>Data is not copied, it's a view of the original array! This avoids memory problems!<jupyter_code>arr_copy = arr.copy()
arr_copy<jupyter_output><empty_output><jupyter_text>Indexing a 2D array(,atrices)<jupyter_code>arr_2d = np.array(([5,10,15],[20,25,30],[35,40,45]))
#Show
arr_2d
#indexing row
arr_2d[1]
#Format is arr_2d[row][col] or arr_2d[row,col]

#Getting individual element value
arr_2d[1][1]
#Getting individual element value
arr_2d[1][1]
#2D array slicing

#Shape(2,2) from top right coner
arr_2d[:2,1:]
#Shape bottom row

arr_2d[2,:]<jupyter_output><empty_output><jupyter_text>Data Processing  Built-in Methods<jupyter_code>import numpy as np<jupyter_output><empty_output><jupyter_text>arange<jupyter_code>np.arange(0,10)
np.arange(0,10,4)<jupyter_output><empty_output><jupyter_text>zeros and ones<jupyter_code>np.zeros(3)
np.zeros((5,5))
np.ones((3,3))
np.ones((5,5))<jupyter_output><empty_output><jupyter_text>linspace<jupyter_code>np.linspace(0,10,3)<jupyter_output><empty_output><jupyter_text>eye<jupyter_code>np.eye(10)<jupyter_output><empty_output><jupyter_text>Random  rand<jupyter_code>np.random.rand(2)
np.random.rand(5,4)<jupyter_output><empty_output><jupyter_text>randn<jupyter_code>np.random.randn(2)
np.random.randn(5,4)<jupyter_output><empty_output><jupyter_text>randint<jupyter_code>np.random.randint(2)
np.random.randint(1,100,10)<jupyter_output><empty_output><jupyter_text>Array Attributes and Methods<jupyter_code>arr = np.arange(1,37)
ranarr = np.random.randint(0,50,10)
arr
ranarr<jupyter_output><empty_output><jupyter_text>Reshape<jupyter_code>arr.reshape(6,6).shape<jupyter_output><empty_output><jupyter_text>max,min,argmax,argmin<jupyter_code>ranarr
ranarr.max()
ranarr.argmax()
ranarr.min()
ranarr.argmin()<jupyter_output><empty_output><jupyter_text>Mathematical Functions  Universal Array Functions<jupyter_code>import numpy as np
arr = np.arange(0,11)
arr
#Taking Square Roots
np.sqrt(arr)
#Calculating exponential (e^)
np.exp(arr)
#same as arr.max()
np.max(arr)
np.log(arr)<jupyter_output>E:\Anaconda3\lib\site-packages\ipykernel_launcher.py:1: RuntimeWarning: divide by zero encountered in log
  """Entry point for launching an IPython kernel.
{'fraction_non_alphanumeric': 0.13331094694425788, 'fraction_numerical': 0.03593015446608462, 'mean_word_length': 10.413793103448276, 'pattern_counts': {'":': 0, '<': 72, '<?xml version=': 0, '>': 72, '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': '18', 'dir': 'jupyter-structured-clean-dedup', 'id': '273934', 'license': 'MIT', 'n_tokens_mistral': 1303, 'n_tokens_neox': 1246, 'n_words': 195, 'path': 'Section 4/Section 4.ipynb', 'repo_name': 'PacktPublishing/Fast-Numerical-Computing-with-Python', 'size': '2978'}