Write a NumPy program to create a 4x4 matrix in which 0 and 1 are staggered, with zeros on the main diagonal.
import numpy as np x = np.zeros((4, 4)) x[::2, 1::2] = 1 x[1::2, ::2] = 1 print(x)
Sample Output:
[[ 0. 1. 0. 1.] [ 1. 0. 1. 0.] [ 0. 1. 0. 1.] [ 1. 0. 1. 0.]]
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Sample Output: