Identity matrix: Difference between revisions
Content added Content deleted
No edit summary |
m (Lowercase title) |
||
Line 1: | Line 1: | ||
{{lowercase title}} |
|||
{{Primitive|=i}} |
{{Primitive|=i}} |
||
Given a positive integer argument ''n'', '''identity matrix''' returns a ''n''×''n'' matrix with ones in the main diagonal and zeros elsewhere. |
Given a positive integer argument ''n'', '''identity matrix''' returns a ''n''×''n'' matrix with ones in the main diagonal and zeros elsewhere. |
||
Revision as of 20:55, 8 July 2022
Identity matrix
=i
Given a positive integer argument n, identity matrix returns a n×n matrix with ones in the main diagonal and zeros elsewhere.
=5
(1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1)
=1
,,1
=0
()
Works in: ngn/k
This primitive is not available in all dialects. There are multiple ways to implement it in K:
im:{t=/:t:!x}
im[4]
(1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1)
im:{(2#x)#1,&x}
im[2]
(1 0
0 1)
im:{(x-1)(0 :':)\~!x} / fast
im[3]
(1 0 0
0 1 0
0 0 1)