Q.9 How to add a border that is filled with 0s around an existing array?

Ans. In order to add a border to an array that is filled with 0s, we first make an array Z and initialize it with zeroes. We first import numpy as np.

Z = np.ones((5,5))

Then, we perform padding on it with the help of pad() function.

Z = np.pad(Z, pad_width=1, mode=’constant’, constant_values=0)

print(Z)


Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *