<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Day 23 Pre-class assignment
Goals for today's pre-class assignment
In this pre-class assignment, you will
Step1:  Task 2
Step2:  Task 3
Step3:  Task 4
Step4:  Task 5
Step6:  Assignment wrapup
Please fill out the form that appears when you run the code below.  You must completely fill this out in order to receive credit for the assignment!
<ASSISTANT_TASK:>
Python Code:
# Put your code here!
import numpy as np
A = np.zeros((10,10), dtype='int')
for i in range(a.shape[0]):
    for j in range(a.shape[1]):
        A[i,j] = i+j
        
print(A)
Explanation: Day 23 Pre-class assignment
Goals for today's pre-class assignment
In this pre-class assignment, you will:
Create and slice multi-dimensional numpy arrays
Plot 2D numpy arrays
Make an animation of 2D numpy arrays
Assignment instructions
First, work through the Numpy 2D array tutorial (Numpy_2D_array_tutorial.ipynb).  
After that, write code to do the following things:
Task 1: Create a 2D Numpy array, named A, that is a 10x10 array integers, each of which is set to 0.  Write a pair of for loops that iterate over A and sets A[i,j] = i + j.  Print that array out to verify that it's behaving as expected - it should look like this:
[[ 0  1  2  3  4  5  6  7  8  9]
 [ 1  2  3  4  5  6  7  8  9 10]
 [ 2  3  4  5  6  7  8  9 10 11]
 [ 3  4  5  6  7  8  9 10 11 12]
 [ 4  5  6  7  8  9 10 11 12 13]
 [ 5  6  7  8  9 10 11 12 13 14]
 [ 6  7  8  9 10 11 12 13 14 15]
 [ 7  8  9 10 11 12 13 14 15 16]
 [ 8  9 10 11 12 13 14 15 16 17]
 [ 9 10 11 12 13 14 15 16 17 18]]
End of explanation
B = A[1::2,1::2]
print(B)
Explanation: Task 2: Use Numpy's array slicing capabilities to create a new array, B, which is a subset of the values in array A.  Specifically, extract every second element in both dimensions in array A, starting with the second element (i.e., index=1) in each dimension.  Store this in  B, and print out array B.  It should look like this:
[[ 2  4  6  8 10]
 [ 4  6  8 10 12]
 [ 6  8 10 12 14]
 [ 8 10 12 14 16]
 [10 12 14 16 18]]
End of explanation
C = B[1:3,:]
print(C)
Explanation: Task 3: Using Numpy's slicing capabilities, extract the second and third rows of array B and store them in a third array, C.  Print out C.  It should look like this:
[[ 4  6  8 10 12]
 [ 6  8 10 12 14]]
End of explanation
def add_neighborhood(arr):
    
    D = np.zeros_like(arr)
    
    for i in range(arr.shape[0]):
        for j in range(arr.shape[1]):
            D[i,j] = arr[i,j]
            if i >= 1:
                D[i,j] += arr[i-1,j]
                
            if i < arr.shape[0]-1:
                D[i,j] += arr[i+1,j]
            if j >= 1:
                D[i,j] += arr[i,j-1]
            if j < arr.shape[1]-1:
                D[i,j] += arr[i,j+1]
    return D
new_array = add_neighborhood(A)
print(A)
print(new_array)
new_array = add_neighborhood(B)
print(B)
print(new_array)
Explanation: Task 4: Write a function, called add_neighborhood(), that:
Takes in an array as an argument
Creates an array, D, that is the same shape and data type as the incoming array but full of zeros.
Loops over all of the elements of the incoming array (using the shape() method to adjust for the fact that you don't know what its size is) and sets D[i,j] equal to the values of A[i,j] plus its four neighbors, A[i+1,j], A[i-1,j], A[i,j+1], A[i,j-1].  If you are at the edge or corner of the array (say, at A[0,0]) do not include any values that go over the edge of the array (into negative numbers or beyond the last index in any dimension).
Return the array D and print it out once it has been returned from the function.
Test this out using array A and B.  When applied to array A, you should get this output:
[[ 2  5  9 13 17 21 25 29 33 27]
 [ 5 10 15 20 25 30 35 40 45 39]
 [ 9 15 20 25 30 35 40 45 50 43]
 [13 20 25 30 35 40 45 50 55 47]
 [17 25 30 35 40 45 50 55 60 51]
 [21 30 35 40 45 50 55 60 65 55]
 [25 35 40 45 50 55 60 65 70 59]
 [29 40 45 50 55 60 65 70 75 63]
 [33 45 50 55 60 65 70 75 80 67]
 [27 39 43 47 51 55 59 63 67 52]]
and when you apply this function to array B, you should get this output:
[[10 18 26 34 30]
 [18 30 40 50 46]
 [26 40 50 60 54]
 [34 50 60 70 62]
 [30 46 54 62 50]]
Note: Make sure that the edges and corners have the right values!
End of explanation
%matplotlib inline
import matplotlib.pyplot as plt
myplot = plt.matshow(A, cmap='hot')
myplot.axes.get_xaxis().set_visible(False)
myplot.axes.get_yaxis().set_visible(False)
Explanation: Task 5: Using the pyplot matshow() method, plot array A in a plot that uses a color map of your choice (that is not the default color map!), and where the axes are invisible.
End of explanation
from IPython.display import HTML
HTML(
<iframe 
	src="https://goo.gl/forms/VwY5ods4ugnwidnG2?embedded=true" 
	width="80%" 
	height="1200px" 
	frameborder="0" 
	marginheight="0" 
	marginwidth="0">
	Loading...
</iframe>
)
Explanation: Assignment wrapup
Please fill out the form that appears when you run the code below.  You must completely fill this out in order to receive credit for the assignment!
End of explanation
<END_TASK>