How do I create an identity matrix with numpy? Is there a simpler syntax than
numpy.matrix(numpy.identity(n))
Also np.eye can be used to create an identity array (In).
For example,
>>> np.eye(2, dtype=int) array([[1, 0], [0, 1]]) >>> np.eye(3, k=1) array([[ 0., 1., 0.], [ 0., 0., 1.], [ 0., 0., 0.]])