in python: Write a function that takes in as an input a 2D numpy array, i.e., a matrix (let us label this ?) and an integer ? >0. The function should verify that the inputs are of valid type. The output is a matrix (call this ?) with the same shape as ?. Each element of ? at row ? and column ? is the average of the neighboring elements at the same location in the matrix ?. The extent of this neighborhood spans rows ?−?,⋯,?−1,?,?+1,⋯,?+? and columns ?− ?,⋯,?−1,?,?+1,⋯,?+?. In other words, the neighborhood is a submatrix centered around the location ?, ? with 2?+1 rows and columns. For the boundary elements, assume th
in python:
Write a function that takes in as an input a 2D numpy array, i.e., a matrix (let us label this ?) and
an integer ? >0. The function should verify that the inputs are of valid type.
The output is a matrix (call this ?) with the same shape as ?. Each element of ? at row ? and
column ? is the average of the neighboring elements at the same location in the matrix ?. The
extent of this neighborhood spans rows ?−?,⋯,?−1,?,?+1,⋯,?+? and columns ?−
?,⋯,?−1,?,?+1,⋯,?+?. In other words, the neighborhood is a submatrix centered around
the location ?, ? with 2?+1 rows and columns. For the boundary elements, assume the matrix is
padded with requisite number of zeros for the purpose of computing the average.
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 2 images