Last active
April 25, 2023 10:39
-
-
Save suhr/c6544330e7a3ae8f7abc4d2d9b2571fc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Syntax | Name | Description | Example | Output | |
---|---|---|---|---|---|
+/x | Sum | Sum all value in x | +/1 2 3 4 5 | 15 | |
-':x | Deltas | Pairwise differences in x | -':1 2 3 4 | 1 1 1 1 | |
|+x | Rotate matrix | Rotate x counterclockwise | |+3 3#!9 | (2 5 8;1 4 7;0 3 6) | |
x@<x | Sort | Sort x | {x@<x}@8 3 7 1 | 1 3 7 8 | |
?x,y | Set union | Unique elements from x and y | ?"abac","adob" | "abcdo" | |
x^x^y | Intersection | Common elements from x and y | {?x^x^y}["abac";"adob"] | "aba" | |
x|-x | Absolute value | Absolute value of x | {x|-x}@-1 | 1 | |
*/y#x | Power | x in power of y (y>0) | {*/y#x}[2;5] | 32 | |
y@(#y)!x+!#y | Rotate left | Rotate y by x elements to the left | {y@(#y)!x+!#y}[3;"abcde"] | "deabc" | |
`c$x-32*~"a{"'x | Uppercase | Upper case of all alphabetic chars | {`c$x-32*~"a{"'x}@"happy" | "HAPPY" | |
@[x;i;:;v] | Update | Update value at x[i] with v | a:+`a`b!(0 1 ; 2 3);@[a;0;:;(3,4)] | +`a`b!(3 1;4 3) | |
|/x | Max, Any | Largest element in x | |/3 5 2 | 5 | |
&/x | Min, All | Smallest element in x | &/3 5 2 | 2 | |
(+/x)%#x | Average | Arithmetic mean | {(+/x)%#x}@1 2 3 4 5 | 3.0 | |
z@y/(!y@<x)x | Permute axes | x⍉y⍴z | {z@y/(!y@<x)x}[2 0 1; 2 3 4; `c$"A"+!24] | "AMBNCODPEQFRGSHTIUJVKWLX" | |
*|x | Last | Last element of x | *|"abc" | "c" | |
*<x | Index of min | Index of smallest element in x | *<"banana" | 1 | |
*>x | Index of max | Index of largest element in x | *>"banana" | 2 | |
*/x | Product | Multiply all values in x | */2 3 4 | 24 | |
*:/x | Deep first | First value in nested array x | *:/(("ab";"cd");("ef";"gh")) | "a" | |
<<x | Ascending ordinals | Rank values in x by smallness | <<"baka" | 2 0 3 1 | |
<>x | Descending ordinals | Rank values in x by greatness | <>"baka" | 1 2 0 3 | |
,/x | Flatten | Remove one level of nesting | ,/(("ab";"cd");("ef";"gh")) | ("ab";"cd";"ef";"gh") | |
,//x | Enlist | Flatten nested array into a list | ,//(("ab";"cd");("ef";"gh")) | "abcdefgh" | |
x@&y | Compress, Replicate | Repeat each value in x y times | "abcd"@&1 0 2 0 | "acc" | |
x@\:y | Apply list | Apply each function in x to y | (2+;3*)@\:!5 | (2 3 4 5 6;0 3 6 9 12) | |
d:#'=x; @[(1+|/x)#0;!d;:;.d] | Where Inverse | Inverse to & | {d:#'=x; @[(1+|/x)#0;!d;:;.d]}@ &0 2 1 | 0 2 1 | |
(!1+#x)#\:x | Prefixes | Prefixes of x | {(!1+#x)#\:x}"abcde" | ("";,"a";"ab";"abc";"abcd";"abcde") | |
(!1+#x)_\:x | Suffixes | Suffixes of x | {(!1+#x)_\:x}"abcde" | ("abcde";"bcde";"cde";"de";,"e";"") | |
x,(-#x)_y | Shift before | Insert x into the start of y, shifting trailing elements out | {x,(-#x)_y}["foo"; "abcde"] | "fooab" | |
((#x)_y),x | Shift after | Insert x into the end of y, shifting leading elements out | {((#x)_y),x}["foo"; "abcde"] | "defoo" | |
(&#'x)@<,/.x | Group inverse | Inverse to = | {(&#'x)@<,/.x}@="banana" | "banana" | |
~x'y | In range | For x~(a;b) is the same as (~a>y)&y<b | ~2 5'!10 | 0 0 1 1 1 0 0 0 0 0 | |
z=x|y&z | In range (inclusive) | Shorter version of (~x>z)&~z>y | {z=x|y&z}[2;5;!10] | 0 0 1 1 1 1 0 0 0 0 | |
~^y?x | Elements of | For each element in of x check if it's in y | ~^"banana"?"bar" | 1 1 0 | |
x@.=x-!#x | Consequents | Consequent sequences of x | {x@.=x-!#x}"abclmxyz" | ("abc";"lm";"xyz") | |
m:&x; y@m@.=m-!#m | Cut by mask | Cut y by mask x | {m:&x; y@m@.=m-!#m}[0 1 1 0 1 1 1; "a42b123"] | ("42";"123") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment