31 July 2020
Code
# Import library
import numpy as np
# Create array - 1
x = np.eye(4)
# Create array - 2
y = np.identity(4)
# Output
print("Using np.eye(): \n", x)
print("\n Using np.identity(): \n", y)
Output
Using np.eye():
[[1. 0. 0. 0.]
[0. 1. 0. 0.]
[0. 0. 1. 0.]
[0. 0. 0. 1.]]
Using np.identity():
[[1. 0. 0. 0.]
[0. 1. 0. 0.]
[0. 0. 1. 0.]
[0. 0. 0. 1.]]
Any errors in code above?
Please send a message.