<jupyter_start><jupyter_text>Solutions1. [NumPy][1]2. [Pandas][2]3. [Seaborn][3]4. [Scikit-Learn][4][1]: 1.-NumPy[2]: 2.-Pandas[3]: 3.-Seaborn[4]: 4.-Scikit-Learn<jupyter_code>import numpy as np
import pandas as pd
import seaborn as sns
%matplotlib inline<jupyter_output><empty_output><jupyter_text>1. NumPy  Problem 1Create an array with 5 rows and 8 columns of random dice rolls. Assign it to variable `arr` and output it to the screen. Set the random number generation seed to 1 before creation.<jupyter_code>np.random.seed(1)
arr = np.random.randint(1, 7, (5, 8))
arr<jupyter_output><empty_output><jupyter_text>Problem 2Select single elements of `arr` multiple times.<jupyter_code>arr[1, 3]
arr[-1, -2]
arr[4, 4]<jupyter_output><empty_output><jupyter_text>Problem 3Select many subsets of elements of `arr` using slice notation.<jupyter_code>arr[2:4, 3:5]
# this selects all of the columns
arr[2:4]
# Select all of the rows
arr[:, 2]<jupyter_output><empty_output><jupyter_text>Problem 4Practice using the basic vectorized arithmetic operations.<jupyter_code>arr / 2
# floor division
arr // 2
# raise to a power
arr ** 2
# modulus - get remainder
arr % 3<jupyter_output><empty_output><jupyter_text>Problem 5Practice calling many of the methods. Use the tab completion help to find them. Change the direction of operation with the **`axis`** parameter.<jupyter_code>arr.std()
arr.argmax()
arr.argmax(axis=0)
arr.cumsum()
# across
arr.cumsum(axis=1)
arr.repeat(3)<jupyter_output><empty_output><jupyter_text>Problem 6Practice calling many NumPy functions. Find them by using tab completion with **`np.`**.  Use the functions that have an array as their first parameter.<jupyter_code>np.arctan(arr)
np.diag(arr)
# Get the 30th percentile of each column
np.percentile(arr, q=.3, axis=0)<jupyter_output><empty_output><jupyter_text>Problem 7Which column has the highest average roll?<jupyter_code># third column
arr.mean(axis=1)
# automate with numpy
arr.mean(axis=1).argmax()<jupyter_output><empty_output><jupyter_text>Problem 8Find the average roll for all rolls. Then find the average roll for each row. Which rows have an average that is higher than the average for all rolls?<jupyter_code>overall_avg = arr.mean()
overall_avg
row_avg = arr.mean(axis=1)
row_avg
row_avg > overall_avg
# get the location of rows that are True
np.where(row_avg > overall_avg)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11153039832285115, 'fraction_numerical': 0.025157232704402517, 'mean_word_length': 6.341538461538462, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 39, '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': '124668', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 885, 'n_tokens_neox': 831, 'n_words': 248, 'path': 'solutions.ipynb', 'repo_name': 'STATWonderWoman/Intro-to-Data-Science-with-Python', 'size': '2385'}