from SimPEG.Utils import speye # Syntax speye(n, format=None) # Example import numpy as np from SimPEG.Utils import speye n = 3 A = speye(n) # Generate an identity matrix of dimension 3 print('Identity Matrix of Dimension {0}:\n {1}'.format(n,A.toarray())) m = 4 n = 5 B = speye(m,n) # Generate an identity matrix of dimension 4x5 print('Identity Matrix of Dimension {0}:{1} :\n{2}'.format(m,n,B.toarray()))
Identity Matrix of Dimension 3: [[1. 0. 0.] [0. 1. 0.] [0. 0. 1.]] Identity Matrix of Dimension 4x5: [[1. 0. 0. 0. 0.] [0. 1. 0. 0. 0.] [0. 0. 1. 0. 0.] [0. 0. 0. 1. 0.]]This function is specifically provided in the SimPEG library for the purpose of generating sparse identity matrices that arise in many scientific and computational applications. The SimPEG Utils package is part of the SimPEG library, which is a Python library for Simulation and Parameter Estimation in Geophysics.