Skip to content

Instantly share code, notes, and snippets.

@adam-nathan
Last active March 9, 2022 16:31
Show Gist options
  • Save adam-nathan/9649dca27c83c3f8e0395b80d4dc669c to your computer and use it in GitHub Desktop.
Save adam-nathan/9649dca27c83c3f8e0395b80d4dc669c to your computer and use it in GitHub Desktop.
Useful functions in APL
segs ← ⊃,/∘(⍳∘≢,/¨⊂)
segs ← (⊃,/)⍳∘⊃∘⌽∘⍴,/¨⊂ ⍝ works for matrix also
freq ← ((⎕C ⎕A)∘.=⊢)
mseg ← {⎕IO←0 ⋄ (⍳∘≢⍵)∘.{⍺↓⍵},\⍵} ⍝ all subvectors in correct position
bits ← 2∘⊥⍣¯1
pdf←{
⍺←(0 1)
nom←*⍤-2÷⍨*∘2
denom←0.5*⍨○2
phi←denom÷⍨nom
(mean sigma)←⍺
sigma÷⍨phi(⍵-mean)÷sigma
}
norm ← ⊢(÷⍤1 0) +/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment