<jupyter_start><jupyter_text>Homework - NumPy - Pandas (15 pts)!!! Do NOT use for loops for array manipulations. ONLY use numpy. 1. (3 pts) Generate 100 random two-dimensional (x,y) points within a unit square (i.e. x and y randomly chosen between 0 and 1) and assign them to the variable **points**. Make sure to store the points as a matrix where the 1st column is the x values and the 2nd column is the y values (i.e. each row is a point). Next shift and scale each point so that its x and y values fall between 5 and 10. The variable **points** should refer to the shifted and scaled values. Print the first five points to verify.<jupyter_code>import numpy as np
import pandas as pd
import math
from sklearn import datasets
points = np.random.random((100,2))
points = points * 5 + 5
print(points[0:5, :])<jupyter_output>[[7.14615726 7.26931708]
 [9.03074147 9.9243736 ]
 [9.46599025 6.19910383]
 [7.00383077 6.08733163]
 [7.47140435 5.26606568]]<jupyter_text>2. (3 pts) In a single operation (do NOT do this in two separate steps), multiply all x values by 2 and divide all y values by 10. Make sure that the variable **points** reflects the changed values. Print the first five points to verify.<jupyter_code>multiply = np.array([2,.1])
points = points * multiply
print(points[0:5, :])<jupyter_output>[[10.15620561  0.63010279]
 [12.18048165  0.69646746]
 [11.02406067  0.60792967]
 [14.51301214  0.83674716]
 [14.65234068  0.83203368]]<jupyter_text>3. (3 pts) Use numpy.linspace to generate 101 equally spaced $x$ values between and including -10 and 10. For each $x$ value, evaluate $y(x) = x^2 + sin(x)$. Store your results in the variables **x** and **y**.<jupyter_code>x = np.linspace(-10, 10, num = 101)
y = [None] * len(x)
for i in range(0, len(x)):
    y[i] = x[i] * x[i] + math.sin(x[i])
# This cell will plot y vs x.
# You don't have to do anything here,
# it's just so you can visualize your result.
import matplotlib.pyplot as plt
plt.plot(x, y)
plt.xlabel("x")
plt.ylabel("y");<jupyter_output><empty_output><jupyter_text>4. (3 pts) Put the **x** and **y** arrays from 3 above into a pandas dataframe where the 1st column is the x values and the 2nd column is the y values. Set the column titles to "x" and "y". Use the *head* and *tail* functions to display the first few and last few points.<jupyter_code>combined = np.column_stack((x,y))
features = "x y".split()
df = pd.DataFrame(combined, columns = features)
print(df.head(4))
print(df.tail(4))<jupyter_output>x           y
0 -10.0  100.544021
1  -9.8   96.406479
2  -9.6   92.334327
3  -9.4   88.335225
        x          y
97    9.4  88.384775
98    9.6  91.985673
99    9.8  95.673521
100  10.0  99.455979<jupyter_text>5. (3 pts) Sort the points in the dataframe from 4 above by increasing y value. Make sure your original dataframe variable reflects the sorted points. Verify by displaying the first three, middle three and last three points.<jupyter_code>df.sort_values(by=['y'], inplace=True)
print(df.head(3))
print(df.tail(3))
print(df.iloc[49:52])<jupyter_output>x         y
48 -0.4 -0.229418
47 -0.6 -0.204642
49 -0.2 -0.158669
        x           y
1    -9.8   96.406479
100  10.0   99.455979
0   -10.0  100.544021
      x          y
75  5.0  24.041076
25 -5.0  25.958924
76  5.2  26.156545
{'fraction_non_alphanumeric': 0.11671249618087381, 'fraction_numerical': 0.13809960281087688, 'mean_word_length': 3.553546592489569, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '495505', 'license': 'Unlicense', 'n_tokens_mistral': 1442, 'n_tokens_neox': 1207, 'n_words': 446, 'path': 'homework/homework-numpy-pandas.ipynb', 'repo_name': 'sathwikiyer/NEU-365P-385L-Spring-2021', 'size': '3273'}