Essays/Identity Matrix

From J Wiki
Jump to navigation Jump to search

Generate the identity matrix of order n , n>0 .


Raze-In

I1=: e.@i.

Outer Product

I2a=: =/~@i.
I2b=: ="1 0~@i.
I2c=: (<: *. >:)"0/~ @ i.
I2d=: (<:/ *. >:/)~ @ i.

Reshape

I3a=: ,~ $ >: {. 1:
I3b=: ,~ $ 1 , $&0
I3c=: ($&0 , 1:)"0@i.

Rotate

I4a=: -@i. |."0 1 {.&1
I4b=: _1&|.^:(i.@#) @ ({.&1)

Shift

I4c=: |.!.0^:(<`({.&1))

Copy

I5a=: 0 1 0 #"1~ i. ,. 1 ,. i.@-
I5b=: 0 1   #"1~ i. ,. 1:

Take

I6=: -@>:@i. {."0 1:

Drop

I7=: i.@- }."0 1 {.&1@-

Prefix

I8a=: |.\ @ ({.&1)
I8b=: |.@~:\ @ ($&0)
I8c=: (={:)\ @ i.

Suffix

I9=: ]\.&.|. @ ({.&1)

Infix

I10=: - ]\ *: $ 1 , $&0

Outfix

I11=: 3 : '-. 1 (i.y)&e.\. i.y'

Oblique

I12=: {. |./.@(#"0 {.&1)

Prepend

I13=: 0&,^:(i.`1:)

Amend

I14a=: 3 : '1 (,&.>~ i.y)} (,~y) $ 0'
I14b=: 1 (<0 1)&|:@i.@$@]} ,~ $ 0:
I14c=: 1 (>: * i.)@#@]} ,~ $ 0:

Membership

I15=: i.@,~ e. >: * i.

Cut

I16=: [: |.;.1 i.@(2&!)@>: e. 2&!@>:@i.

Indices of Ravel

I17a=: 0 = >: | i.@,~
I17b=: i.@,~ = >: * i.

Row and Column Indices

I18a=: =/&> @ { @ (;~) @ i.
I18b=: =/"1@(#:i.)@,~

Transpose

I19a=: (=|:) @ i. @ ,~
I19b=: (=|:) @ (-/~) @ i.

Binary Representation

I20a=: #: @ (2&^) @ i. @ -
I20b=: [: #: +:^:(i.@-`1:)

Anagram

I21=: |.!.''@:(+/\)@:!@:i.@:- A. {.&1

Cycle

I22=: ~.@(0&,)&.>@i. C."0 1 {.&1

Vector Calculus

I23=: ]D.1@i.

Polynomial

I24=: p.@($&0&.>)@i.

Matrix Multiplication

The identity matrix is the neutral for matrix multiplication.

I25=: +/ .*/ @ i. @ (0&,)

Random Matrix

The probability of the adverse being invoked is very small and decreases with increasing matrix size.

I26=: (+/ .* %.)@(,~ ?@$ 2147483647x"_) :: $:

Recursion

I27=: 3 : 0
 if. 1=y do. 1 1$1 else. (,~y) {. ((,. , ,.~) 0*]) I27 >.-:y end.
)

Interval Member

I28=: E."0 1~@i.

Power Take

I29=: ({.~ -@>:@#)^:(<`1:)

Double Antibase

I30=: +:&.#.&.|. ^: (<`1:)

Function Table Diagonal

I32a=: (1   =  =/~)@i.   NB. 1      Equal
I32b=: (0   = ~:/~)@i.   NB. 0      Not equal
I32c=: (+:  =  +/~)@i.   NB. Double Addition
I32d=: (0   =  -/~)@i.   NB. 0      Subtraction
I32e=: (*:  =  */~)@i.   NB. Square Multiplication
I32f=: (1   =  %/~)@i.   NB. 1      Division
I32g=: (1   =  !/~)@i.   NB. 1      Out Of
I32h=: (j.~ = j./~)@i.

Primes and Factoring

I33=: _&q: @ p: @ i.

Self-Classify

The self-classification of an array with all distinct items is the identity matrix. Thus:

I0a=: =@i.
I0b=: =@?~

The self-classify verb = y is deprecated, because its function is better performed by i.~ y .