Apl2ToDoStructuralAlgorithms

This is a sub-page of PhraseBook/ToDo/Apl2Idioms

A←(' ',S)[BA] ⍝ Build array from boolean pattern. Insert S.

A←(' ',S)[1+BA] ⍝ Build array from boolean pattern. Insert S.

A←(' ',V)[BA×(⍴BA)⍴⍳¯1↑⍴BA] ⍝ Build array from boolean pattern. Insert V.

A←(' ',V)[1+BA×(⍴BA)⍴⍳¯1↑⍴BA] ⍝ Build array from boolean pattern. Insert V.

A←⊃⊃,/¨(⊂[1]BM)⊂¨⊂V ⍝ Build array from boolean pattern. Reduce A.

A←⊃⊃,/¨(⊂[2]BM)⊂¨⊂V ⍝ Build array from boolean pattern. Reduce A.

A←1/A ⍝ Change A, only if it is scalar, to vector.

A←1/¨A ⍝ Change scalars to vectors at depths 0-2.

AA←(⌈/(-⌈/⍴¨⍴¨AA)↑¨⍴¨AA)⍴¨AA ⍝ Force each item to same shape by reshape.

AV←(⌈/⍴¨AV)↑¨AV ⍝ Force each item to same shape by overtake.

A←,['']A ⍝ Ghost Buster. Inc rank by one on last dim.

A←,[¯.5]A ⍝ Increase rank by one on the first dim.

A←,[.5]A ⍝ Increase rank by one on the first dim.

A←,[IS+.5]A ⍝ Increase rank by one after dim IS.

A←((-⍴⍴AY)↑((⍴⍴AY)⍴1),⍴AX)⍴AX ⍝ Increase rank of AX to rank of AY.

A←,[2↑⍳⍴⍴A]A ⍝ Decrease rank of A by 1. Rank 2 or higher.

AV←⊂[¯1+(0≠⍴⍴A)/⍴⍴A]A ⍝ Decrease rank of A by 1.

AV←⊂[(0≠⍴⍴A)/⍴⍴A]A ⍝ Decrease rank of A by 1.

A←(⍋(-⍴⍴A)↑1 0)⍉A ⍝ Transpose every submatrix of A.

IO←⍴,A ⍝ Number of elements in A as vector.

IS←×/⍴A ⍝ Number of elements in A.

IS←×/1↓⍴A ⍝ Number of elements in a plane of 3D A.

IO←¯1↑⍴A ⍝ Number of columns in A as vector.

IS←↑⌽⍴A ⍝ Number of columns in A.

IO←1↑⍴M ⍝ Number of rows in M as vector.

IS←↑⍴M ⍝ Number of rows in M.

I←⍳⍴⍴A ⍝ All axes of array A.

I←⍳¯1↑⍴A ⍝ All column indices of array A.

I←⍳↑⍴M ⍝ All row indices of matrix M.

I←⍳⍴V ⍝ All indices of vector V.

IO←⍴⍴A ⍝ Rank of A.

AV←⍴¨⍴¨AA ⍝ Rank of each item in an array.

IO←↑⍴¨⍴¨AA ⍝ Rank of the first item in an array.

IO←⍴⍴↑AA ⍝ Rank of the first item in an array.

(,A)←⊂AX ⍝ Replace all items, shape unchanged.

(B/,A)←(+/B)⍴V ⍝ Replace selected items, shape unchanged.

A←↑A ⍝ The first item in any rank array.

A←↑⌽,A ⍝ The last item in any rank array.

A←↑0⍴⊂↑A ⍝ The prototype of A.

A←↑0⍴⊂A ⍝ The type of A.

IO←1+(0,⍴,A)⍳0+.=↑¨0⍴¨,A ⍝ Type of simple A. 1-char, 2-num, 3-mixed.

IO←(0,⍴,A)⍳0+.=↑¨0⍴¨,A ⍝ Type of simple A. 1-char, 2-num, 3-mixed.

B←Aε⍳0 ⍝ Zeros, same shape when A is simple.

B←A≠A ⍝ Zeros, same shape and structure.

B←0+/V ⍝ Zeros, same shape plus one.

B←A=A ⍝ Ones, same shape and structure.

B←0×/V ⍝ Ones, same shape plus one.


CategoryPhrasebookToDo

Apl2ToDoStructuralAlgorithms (last edited 2011-04-25 13:56:10 by KaiJaeger)