Julia Reference Card

ADVERTISEMENT

Julia Reference Card
42 0x2A 0o52 0b101010
42 (dec,hex,oct,bin,)
1.4 Sets
v0.9.2
round(x,n)
round x to n dec places
s=Set(s...)
create set
(c) 2013 John Lynch modeled on M Goerz's Python card to help map Python to Julia
int() int8() to int128()
int from string or num
s=IntSet(i...)
create sorted int set
Information taken liberally from the Julia documentation and various other sources.
float("3.14")
float16()
float from string or num
You may freely modify and distribute this document.
add!(s,key)
add an element
1 Variable Types
float32() float64()
issubset(s,t); s<=t
all s in t?
string(3.14)
conversion
union!(s,t)
array if t is array
1.0 On All Objects or Collections (c)
hex(n)
dec(n)
oct(n)
create hex, dec, oct,
intersect(s,t)
elements in s and t
is(a, b) or ===
object identity
base(b,n)
base b string
setdiff!(s,t) | (s,c)
all s not in t
isequal(x,y) or ==
value identity
int('x')
code point of char
symdiff!(s,t) | (s,n) (s,c)
all either s excl or t
isa(x, type)
test if x is a type
1.2 Sequences
(arrays are mutable, tuples and strings
complement!(s)
set-complement intset
isless(x,y)
consistent x<y test
are immutable). 1 dimensional arrays (column) replace
1.5 Strings and Regular Expressions
typeof(x)
get x's concrete type
vectors and arrays are indexed from 1 to end. Arrays use []
"bla"; 'hello "world"'
string (of bytes)
tuple(x's)
tuple([]...)
create tuple
but heterogeneous arrays, cells, use {} and can replace lists.
\\
backslash
ntuple(n, f::Function)
tuple f(i) for i:n
a=l=[1, 2, 3, 4] or []
create 1 dim Array
\N{id} \uhhhh \Uhhhhhhhh
unicode char
object_id(x) ; hash(x)
id equiv to === & ==
s=l={1,"ba",{1+2im,1.4}, 4}
list or 1d cell creation
\xhh
hex
copy(x) ; deepcopy(x)
shallow or recursive copies
s=t=(1,"ba",[1+2J,1.4], 4)
tuple creation
'\u78' '\u2200'
'\U10ffff'
unicode string
eltype(d)
type of elements
s=l=linspace(start, stop, n)
n items between start & ...
eval ; evalfile
evaluate expression
l=[t...] ; t=tuple(l...)
list / tuple conversion
@sprintf("%Fmt", args...)
string formatting
collect(c) ; (c...)
array of all items with
s=1:1000
range of integers
%s
%03d
%.2f
%+.0e
%E
string, int 3char + lead
k,v tuples for dicts
a=[1:1000]
1d array of ints
zero, float 2 precision
s=[c,x] ; s=vcat(c,x)
Add to s vertically
s[3][1]
get element (1+2im)
t="eat" ; "$t here"
var interpolation
s=[c x] ; s=hcat(c,x)
Add horizontally
l[end-1][end]
get element (1.4)
s*s ; *(s,s1,s2)
concatenate strings
hvcat(a,r,c) ; [a b;c d;..]
Concatenate r+c
s[i:j]; s[i:]; s[:j]
slicing (i & j inclusive)
s^n ; ^(s,n)
repeat s n times
empty!(c) ; isempty(c)
empty or test c
s[i:k:j]
; eg s[0:2:10]
slice with stride k
join((s,s,s),sep)
join string with separator
x in s; in(s,x);
!in(s,x)
is x a member of s
s[j:-k:i] ; eg s[9:-1:1]
reverse slice eg 9 to 1
collect(s)
return an array from
length(c)
; endof(c)
length and last index of c
s[2:2:]
; s[1:3:end]
every 2
nd
; every 3
rd
utf8(s)
s to utf-8 string
size(c[,d])
size of c in dimension d
l[i:j]=['a','b','c','d']
replace equal slice
char(i)
char from code point
sum(c[,d]) ; prod(c[,d])
fn over dimensions
fill!(c,x)
fill A with value x
push!(a,x)
x = pop!(a)
Add/remove end of a
Other String Methods:
unshift!(a,x)
x = shift!(a)
Add/remove start of a
search & replace: search(s,pat,i), rsearch(s,pat,i),
minimum(c[,d]); maximum
of seq or array (with dims)
append!(l,l2) ; prepend
add items in l2 at end of l
in(pat,s) index(s,pat,i), rindex(s,pat,i),
findmin(c) ; findmax
returns max and index
insert!(l,i,x)
insert x at pos. i
beginswith(s,pat), endswith(s,pat),
any(c[,dims]) ; all
boolean tests
splice!(a,i:j[,newarray])
remove i to j
replace(string, pat, r[, n])
count(f(x),x)
num where f(x) is true
reverse!(1,i,j)
reverse l from i to j
formatting: lowercase, uppercase, ucfirst, lcfirst
first(c) ; last(c)
O(1) first or last element
sort!(l)
sort (many options)
splitting: split(s,m), rsplit(s,m), chop, chomp
getindex(c,i)
get value at index i
zip(s,t,...)
[(s[0],t[0],...),..]
padding: lpad(s,n,p), rpad(s,n,p), lstrip(s,c),
unique(c)
ordered array of uniques
1.3 Dictionaries
rstrip(s,c), strip(s,c)
d={'x'=>42,'y'=>3.14,'z'=>7}
dict creation
checking: isalnum, isalpha, isascii, isblank, iscntrl,
filter(f(x),c) or f(k,v)
return items where true
d={i => f(i) for i=1:n}
using comprehension
isdigit, isgraph, islower, isprint, ispunct,
filter!(f(x),c)
or update collection
[] for inferred types
{} for any type
isspace, isupper, isxdigit
map(f,c) map!(f,c)
transformations
d['x']
get entry for key 'x'
Regexes:
reduce(op,v0,c) ;
reduce with operator
length(d)
number of keys
rm=match(r"regex",s,i)
1
st
. nothing if no match
mapreduce(f,op,c)
from init value v0
delete!(d,'x')
delete entry from dict
rm.match
substring matched
1.1 Numbers
has_key(d, k)
does key exist?
rm.captures
tuple of matches
42 0x2A 0o52 0b101010
42 (dec,hex,oct,bin,)
keys(d)
iter of all keys
rm.offset
offset to match
0.2 .8 4. 1e10 1e-7 3.2f0
floating point value
values(d)
iter of all values
rm.offsets
vector of offsets
Inf NaN
collect(d)
array of keys / values
matchall(r"",s) -> [s s ...]
vector of matches
z = 5 – 2im
complex number
get(d,k,x)
get value, default x
eachmatch(r"",s[,o]) -> iter
iterator over matches
z = complex(real, imag)
complex number
getkey(d,k,x)
get key, default to x
flags after the double quote
real(z); imag(z)
real and imag part of z
merge(dict, ...)
merge dicts
i
case insensitive
2//3 - 1//2
rational numbers (gcd)
pop!(d,k,x)
return & delete item
m
multiline string
true; false
boolean constants
s
single line string
abs(n)
absolute value of n
x
ignore whitespace
divrem(x, y)
(x/y, x%y)
cmp(x,y)
x<y: -1, x==y: 0, x>y: 1

ADVERTISEMENT

00 votes

Related Articles

Related forms

Related Categories

Parent category: Education
Go
Page of 2