<jupyter_start><jupyter_text>Introduction to numpy and matplotlibYou should already be familiar with the standard python types such as lists and dictionaries.In this notebook we will demonstrate how numpy provides arrays (matrices) and convenient ways to perform operations on them. Recall the equation for a straight line $y = mx+c$, where $m$ denotes the slope and $c$ the intercept. Note, as you come to encounter linear regression, where $m$ and $c$ are unknown parameters to be determined from data, you will see $m$ typically replaced with $\beta_1$ and $c$ with $\beta_0$, where $\beta_i$ denotes a parameter to be determined. Thus the straight line formula will be written $y = \beta_1x + \beta_0$ or $y = \beta_0 + \beta_1x$. These two forms, of course, being mathematically equivalent. The basic task we set ourselves here is to take an input sequence of numbers (multiple $x$ values) and create an output sequence (multiple $y$ values). We'll take the desired slope of the line to be 5 and the intercept -1.<jupyter_code>m = 5
c = -1
x = [0, 1, 2, 3, 4, 5, 6]<jupyter_output><empty_output><jupyter_text>Here we hold our multiple $x$ values in a python list.<jupyter_code># task: use a list comprehension to create the output y values
# note how we can't simply write y = m*x + c
# one line of code here:
y = [m*x+c for x in range(len(x))]
print(y)<jupyter_output>[-1, 4, 9, 14, 19, 24, 29]<jupyter_text>Although list comprehensions are very "pythonic", they are more cumbersome than we'd like for performing lots of numeric, or matrix, operations.  numpyLet's now perform the above using numpy.<jupyter_code># task: import numpy
# one line of code here:
import numpy as np
X = np.array(x)
Y = m*X + c
print(Y)<jupyter_output>[-1  4  9 14 19 24 29]<jupyter_text>Notice how we can now write the code in a much more mathematical way.  matplotlibNow we have our matching input and output values, X and Y, wouldn't it be nice to see them in a graph. Although the plot function is very useful for sequences, in our case here we have a sequence of points that all lie on a straight line. This means it will be impossible in a plain line plot to tell whether there is one straight line between two endpoints, or a series of points. It can be more informative to show the individual points, and so here we will use a scatter plot rather than a line plot.<jupyter_code>import matplotlib.pyplot as plt
# task: create a scatter plot of X and Y
# Hint: either refer to matplotlib documentation or, after importing pyplot, use Jupyter's autocompletion
# suggestions to find the relevant scatter plot function
# one line of code here
plt.scatter(X,Y)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.07025411061285501, 'fraction_numerical': 0.014573991031390135, 'mean_word_length': 4.635789473684211, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '603939', 'license': 'CNRI-Python', 'n_tokens_mistral': 803, 'n_tokens_neox': 755, 'n_words': 420, 'path': '02_numpy_matplotlib.ipynb.ipynb', 'repo_name': 'ashu0067/intern_training', 'size': '2676'}