<jupyter_start><jupyter_text>![title](img/cover4.png) Copyright! This material is protected, please do not copy or distribute.    by:<NAME> ***Udemy course : Python Bootcamp for Data Science 2021 Numpy Pandas & Seaborn ***  6.8 Fancy Indexing First we import numpy library:<jupyter_code>import numpy as np<jupyter_output><empty_output><jupyter_text>Here we create a numpy array using the numpy function random.randint<jupyter_code>array1 = np.random.randint(50, size= 10)
array1<jupyter_output><empty_output><jupyter_text>To Use Fancy indexing, we can create any index to be used to slice the data, like this one<jupyter_code>ind = [1,3,5,7]<jupyter_output><empty_output><jupyter_text>Here we used the index that we created int the last code line to select a subset of the array1<jupyter_code>array1[ind]<jupyter_output><empty_output><jupyter_text>We can create an index with different shapes, here we create a two-dimentional index:<jupyter_code>ind2 = np.array([[1,3], [5,7]])
ind2<jupyter_output><empty_output><jupyter_text>We can use the created two-dimentional inde to slice array1, like this:<jupyter_code>array1[ind2]<jupyter_output><empty_output><jupyter_text>Now lets create a two-dimensional array:<jupyter_code>array2 = np.random.randint(100, size=(3,4))
array2<jupyter_output><empty_output><jupyter_text>To slice two-dimensional array, We create an index that contains two sets, one for rows and one for columns:<jupyter_code>ind = ((0,1,2),(3,2,3))
ind
array2[ind]<jupyter_output><empty_output><jupyter_text>We can also create two separate indexes, one for rows and one for columns:<jupyter_code>row = [0,1,2]
column = [3,2,3]
array2[row,column]<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10722748815165876, 'fraction_numerical': 0.029028436018957347, 'mean_word_length': 7.98404255319149, 'pattern_counts': {'":': 0, '<': 38, '<?xml version=': 0, '>': 38, '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': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '655701', 'license': 'MIT', 'n_tokens_mistral': 606, 'n_tokens_neox': 592, 'n_words': 160, 'path': '6.8 Fancy Indexing.ipynb', 'repo_name': 'SiamakMushakhian/Numpy-Pandas-Seaborn', 'size': '1693'}