Sync
This commit is contained in:
parent
6f050a029e
commit
776bba907c
3887 changed files with 59894 additions and 7280 deletions
|
|
@ -1,5 +1,6 @@
|
|||
def identity(size):
|
||||
matrix = [[0] * size] * size
|
||||
matrix = [[0]*size for i in range(size)]
|
||||
#matrix = [[0] * size] * size #Has a flaw. See http://stackoverflow.com/questions/240178/unexpected-feature-in-a-python-list-of-lists
|
||||
|
||||
for i in range(size):
|
||||
matrix[i][i] = 1
|
||||
|
|
|
|||
|
|
@ -1 +1,11 @@
|
|||
np.mat(np.eye(size))
|
||||
>>> def identity(size):
|
||||
... return {(x, y):int(x == y) for x in range(size) for y in range(size)}
|
||||
...
|
||||
>>> size = 4
|
||||
>>> matrix = identity(size)
|
||||
>>> print('\n'.join(' '.join(str(matrix[(x, y)]) for x in range(size)) for y in range(size)))
|
||||
1 0 0 0
|
||||
0 1 0 0
|
||||
0 0 1 0
|
||||
0 0 0 1
|
||||
>>>
|
||||
|
|
|
|||
1
Task/Identity-matrix/Python/identity-matrix-3.py
Normal file
1
Task/Identity-matrix/Python/identity-matrix-3.py
Normal file
|
|
@ -0,0 +1 @@
|
|||
np.mat(np.eye(size))
|
||||
Loading…
Add table
Add a link
Reference in a new issue