<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Further Python Basics
Step1:  Magics!
% and %% magics
interact
embed image
embed links, youtube
link notebooks
Check out http
Step3:  Numpy
If you have arrays of numbers, use numpy or pandas (built on numpy) to represent the data. Tons of very fast underlying code.
Step4:  Matplotlib and Numpy
<ASSISTANT_TASK:>
Python Code:
names = ['alice', 'jonathan', 'bobby']
ages = [24, 32, 45]
ranks = ['kinda cool', 'really cool', 'insanely cool']
for (name, age, rank) in zip(names, ages, ranks):
    print(name, age, rank)
for index, (name, age, rank) in enumerate(zip(names, ages, ranks)):
    print(index, name, age, rank)
# return, esc, shift+enter, ctrl+enter
# text keyboard shortcuts -- cmd > (right), < left,
# option delete (deletes words)
# keyboard shortcuts
#  - a, b, y, m, dd, h, ctrl+shift+-
%matplotlib inline
%config InlineBackend.figure_format='retina'
import matplotlib.pyplot as plt
# no pylab
import seaborn as sns
sns.set_context('talk')
sns.set_style('darkgrid') 
plt.rcParams['figure.figsize'] = 12, 8  # plotsize 
import numpy as np
# don't do `from numpy import *`
import pandas as pd
# If you have a specific function that you'd like to import
from numpy.random import randn
x = np.arange(100)
y = np.sin(x)
plt.plot(x, y);
%matplotlib notebook
x = np.arange(10)
y = np.sin(x)
plt.plot(x, y)#;
Explanation: Further Python Basics
End of explanation
%%bash
for num in {1..5}
do
    for infile in *;
    do
        echo $num $infile
    done
    wc $infile
done
print("hi")
!pwd
!ping google.com
this_is_magic = "Can you believe you can pass variables and strings like this?"
!echo $this_is_magic
hey
Explanation: Magics!
% and %% magics
interact
embed image
embed links, youtube
link notebooks
Check out http://matplotlib.org/gallery.html select your favorite.
End of explanation
x = np.arange(10000)
print(x)  # smart printing
print(x[0]) # first element 
print(x[-1]) # last element
print(x[0:5]) # first 5 elements (also x[:5])
print(x[:]) # "Everything"
print(x[-5:]) # last five elements
print(x[-5:-2])
print(x[-5:-1]) # not final value -- not inclusive on right
x = np.random.randint(5, 5000, (3, 5))
x
np.sum(x)
x.sum()
np.sum(x)
np.sum(x, axis=0)
np.sum(x, axis=1)
x.sum(axis=1)
# Multi dimension array slice with a comma
x[:, 2]
y = np.linspace(10, 20, 11)
y
np.linspace?
np.linspace()
# shift-tab; shift-tab-tab
np.
def does_it(first=x, second=y):
    This is my doc
    pass
y[[3, 5, 7]]
does_it()
num = 3000
x = np.linspace(1.0, 300.0, num)
y = np.random.rand(num)
z = np.sin(x)
np.savetxt("example.txt", np.transpose((x, y, z)))
%less example.txt
!wc example.txt
!head example.txt
#Not a good idea
a = []
b = []
for line in open("example.txt", 'r'):
    a.append(line[0])
    b.append(line[2])
    
a[:10] # Whoops! 
a = []
b = []
for line in open("example.txt", 'r'):
    line = line.split()
    a.append(line[0])
    b.append(line[2])
    
a[:10] # Strings! 
a = []
b = []
for line in open("example.txt", 'r'):
    line = line.split()
    a.append(float(line[0]))
    b.append(float(line[2]))
    
a[:10] # Lists!
# Do this!
a, b = np.loadtxt("example.txt", unpack=True, usecols=(0,2))
a
Explanation: Numpy
If you have arrays of numbers, use numpy or pandas (built on numpy) to represent the data. Tons of very fast underlying code.
End of explanation
from numpy.random import randn
num = 50
x = np.linspace(2.5, 300, num)
y = randn(num)
plt.scatter(x, y)
y > 1
y[y > 1]
y[(y < 1) & (y > -1)]
plt.scatter(x, y, c='b', s=50)
plt.scatter(x[(y < 1) & (y > -1)], y[(y < 1) & (y > -1)], c='r', s=50)
y[~((y < 1) & (y > -1))] = 1.0
plt.scatter(x, y, c='b')
plt.scatter(x, np.clip(y, -0.5, 0.5), color='red')
num = 350
slope = 0.3
x = randn(num) * 50. + 150.0 
y = randn(num) * 5 + x * slope
plt.scatter(x, y, c='b')
# plt.scatter(x[(y < 1) & (y > -1)], y[(y < 1) & (y > -1)], c='r')
# np.argsort, np.sort, complicated index slicing
dframe = pd.DataFrame({'x': x, 'y': y})
g = sns.jointplot('x', 'y', data=dframe, kind="reg")
Explanation: Matplotlib and Numpy
End of explanation
<END_TASK>