Skip to content

Instantly share code, notes, and snippets.

@wsricardo
Last active July 10, 2017 16:19
Show Gist options
  • Save wsricardo/8612cd5404fe60971c8610c3e584aabb to your computer and use it in GitHub Desktop.
Save wsricardo/8612cd5404fe60971c8610c3e584aabb to your computer and use it in GitHub Desktop.
Indentity Matrix in Python
m, n = 3 , 3
# Create matrix
# B = [ [ 0 for i in range(m)] for j in range(n) ]
A = [ [ 1 if i==j else 0 for i in range(m)] for j in range(n)]
# Output: >>> [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
print('\n',A[0],'\n',A[1],'\n',A[2],'\n')
@wsricardo
Copy link
Author

matrix-python2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment