Python NumPy: Create a 3-D array with ones on the diagonal and zeros elsewhere
Python NumPy: Array Object Exercise-42 with Solution
Write a Python program to create a 3-D array with ones on the diagonal and zeros elsewhere.
import numpy as np x = np.eye(3) print(x)
[[ 1. 0. 0.] [ 0. 1. 0.] [ 0. 0. 1.]]
Python Code Editor:
Improve this sample solution and post your code through Disqus