<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 NumPy and Matplotlib Tutorial
Step1:  NumPy Arrays
Creation
Step2:  Create arrays with array, ones, zeros, empty.
Create 1D-arrays with arange, linspace, logspace.
Create arrays/matrices with the same shape as another with zeros_like, ones_like and empty_like.
Get the shape of an array with a.shape (not a function!)
Access
Step3:  Arrays can be accessed like lists (index, slicing).
Slices can be written to!
Can only contain objects of the same type.
Can not change the shape.
Array Math
Step4:  Math operations and functions in NumPy all work elementwise with arrays.
Own functions can be written to support both numbers and numpy arrays!
More NumPy functions
NumPy contains various functions to work with arrays (sorting, FFT, ...)
Matplotlib
Simple Plots
Step5:  plot to plot numpy arrays.
Have a look at the matplotlib gallery to see how to style the plots.
Subplots
Step6:  Subplots can be created.
The number gives the plot grid and the number of the active subplot.
Log and Linear Scales
<ASSISTANT_TASK:>
Python Code:
from __future__ import print_function
from numpy import *
from matplotlib.pylab import *
%pylab --no-import-all inline
Explanation: NumPy and Matplotlib Tutorial
End of explanation
a1 = array([1.0, 2.0, 3.0])
a2 = arange(1.0, 5.0, 0.5)
a3 = linspace(1.0, 10.0, 17)
print(a1)
print(a2)
print(a3)
m1 = array([[1.0, 2.0], 
            [3.0, 4.0]])
print(m1)
a4 = ones(10)
m2 = zeros((5,5))
a5 = empty(10)
print(a4)
print(m2)
print(a5)
a7 = ones_like(a1)
m2 = zeros_like(m1)
# zeros_like, empty_like
print(a7)
print(m2)
print(a7.shape)
print(m1.shape)
Explanation: NumPy Arrays
Creation
End of explanation
print(a1[1])
print(a2[1:7])
print(a3[2::3])
print(a2)
a2[3] = 7.0
print(a2)
a2[3:5] = 2.0
print(a2)
m3 = zeros((10,10))
m3[5,:] = arange(0.0, 10.0)
print(m3)
m3[2:4,:] = 42.0
print(m3)
m3[3:9, 5:7] = 23.0
print(m3)
m4 = ones((10,10))
m4[ [2,7],: ] = 42.0
m4[ :, [3,4] ] = 42.0
print(m4)
m4[5,:] = 23.0
print(m4)
# swap lines!
m4[ [5,2],: ] = m4[ [2,5],: ]
print(m4)
Explanation: Create arrays with array, ones, zeros, empty.
Create 1D-arrays with arange, linspace, logspace.
Create arrays/matrices with the same shape as another with zeros_like, ones_like and empty_like.
Get the shape of an array with a.shape (not a function!)
Access
End of explanation
a1 = ones((10,10))
a2 = a1 + a1
print(a2)
a3 = 2*a2 - a1/2.
print(a3)
print(sin(2.0))
xs = linspace(0.0, 2*pi, 10)
print(sin(xs))
def f(x):
    return x**2 + 1.0
print(f(2.0))
print(f(2*ones(10)))
Explanation: Arrays can be accessed like lists (index, slicing).
Slices can be written to!
Can only contain objects of the same type.
Can not change the shape.
Array Math
End of explanation
xs = linspace(0.0, 2*pi, 100)
plot(sin(xs))
figure()
plot(xs, sin(xs))
# define size of the figure
#rcParams['figure.figsize'] = 10, 7
plot(xs, sin(xs), 'o-', label="sin(x)")
plot(xs, cos(xs), 'rx--', label="cos(x)")
xlabel("x")
ylabel("f(x)")
legend()
Explanation: Math operations and functions in NumPy all work elementwise with arrays.
Own functions can be written to support both numbers and numpy arrays!
More NumPy functions
NumPy contains various functions to work with arrays (sorting, FFT, ...)
Matplotlib
Simple Plots
End of explanation
subplot(221)
plot(xs, sin(xs))
subplot(222)
plot(xs, cos(xs))
subplot(223)
plot(xs, exp(xs))
subplot(224)
plot(xs, log(xs))
Explanation: plot to plot numpy arrays.
Have a look at the matplotlib gallery to see how to style the plots.
Subplots
End of explanation
xs = linspace(1.0, 10.0, 100)
subplot(221)
plot(xs)
plot(xs**2)
plot(0.001*exp(xs))
subplot(222)
loglog(xs)
loglog(xs**2)
loglog(exp(xs))
subplot(223)
semilogy(xs)
semilogy(xs**2)
semilogy(0.001*exp(xs))
subplot(224)
semilogx(xs)
semilogx(xs**2)
semilogx(0.001*exp(xs))
Explanation: Subplots can be created.
The number gives the plot grid and the number of the active subplot.
Log and Linear Scales
End of explanation
<END_TASK>