NUMPY BASIC EXERCISE 13
Create a 5×5 array of zeros, ones and 4s
In this exercise, we are going to create a 5×5 array of zeros, ones and 4s
Code
import numpy as np arr = np.zeros((5, 5)) print("5x5 array of zeros") print(arr) arr = np.ones((5, 5)) print("5x5 array of ones") print(arr) arr = np.full((5, 5), 4) print("5x5 array of 4s") print(arr)
Output
import numpy as np
arr = np.zeros((5, 5))
print("5x5 array of zeros")
print(arr)
arr = np.ones((5, 5))
print("5x5 array of ones")
print(arr)
arr = np.full((5, 5), 4)
print("5x5 array of 4s")
print(arr)