Professional Documents
Culture Documents
http://mathesaurus.sourceforge.net/idl-numpy.html
or man,'plot
help(plot)
or ?plot
help(pylab) demo
Browse help interactively Help on using help Help for a function Help for a toolbox/library package Demonstration examples
Using interactively
IDL idlde Python ipython -pylab TAB @"foo.idlbatch" help,/rec journal,'IDLhistory' exit Description
or .run
or run
foo.py
or CTRL-D
Start session Auto completion Run code from file Command history Save command history End session
Operators
IDL Python Description
Arithmetic operators
IDL a=1 & b=1 a + b a - b a * b a / b a ^ b Python a=1; b=1 a + b a a * a / Description
a ** b power(a,b)
1 of 13
2/4/2014 2:52 PM
http://mathesaurus.sourceforge.net/idl-numpy.html
Remainder
or a+=1 or add(a,b,a)
Increment, return new value Increment, return old value In place operation to save array creation overhead
Relational operators
IDL a eq b a lt b a gt b a le b a ge b a ne b Python a == b a a a a a Description
or equal(a,b) < b or less(a,b) > b or greater(a,b) <= b or less_equal(a,b) >= b or greater_equal(a,b) != b or not_equal(a,b)
Equal Less than Greater than Less than or equal Greater than or equal Not Equal
Logical operators
IDL Python a and b a or b a and b a or b a xor b not a Description
or a and logical_or(a,b) or a or b
logical_and(a,b) logical_xor(a,b) logical_not(a)
or not
Short-circuit logical AND Short-circuit logical OR Element-wise logical AND Element-wise logical OR Logical EXCLUSIVE OR Logical NOT
Square root Logarithm, base $e$ (natural) Logarithm, base 10 Logarithm, base 2 (binary) Exponential function
Round off
IDL round(a) ceil(a) floor(a) Python around(a) ceil(a) floor(a) fix(a) Description
or math.round(a)
2 of 13
2/4/2014 2:52 PM
http://mathesaurus.sourceforge.net/idl-numpy.html
Mathematical constants
IDL !pi exp(1) Python math.pi math.e Description
or math.exp(1)
$\pi=3.141592$ $e=2.718281$
Not a Number Infinity, $\infty$ Infinity, $+\infty$ Infinity, $-\infty$ Plus zero, $+0$ Minus zero, $-0$
Complex numbers
IDL complex(0,1) z = complex(3,4) abs(z) real_part(z) imaginary(z) conj(z) Python z = 1j z = 3+4j Description
or z
= complex(3,4)
Imaginary unit A complex number, $3+4i$ Absolute value (modulus) Real part Imaginary part Complex conjugate
Trigonometry
IDL Python atan2(b,a) hypot(x,y) Description
Uniform distribution Uniform: Numbers between 2 and 7 Uniform: 6,6 array Normal distribution
random.uniform(0,1,(6,6)) random.standard_normal((10,))
Vectors
IDL Python Description
3 of 13
2/4/2014 2:52 PM
http://mathesaurus.sourceforge.net/idl-numpy.html
a = [2, 3, 4, 5]
a=array([2,3,4,5])
transpose([2,3,4,5])
Sequences
IDL indgen(10)+1 dindgen(10)+1 dindgen(10) indgen(4)*3+1 Python arange(1,11, dtype=Float) range(1,11) arange(10.) arange(1,11,3) arange(10,0,-1) arange(10,0,-3) linspace(1,10,7) Description
1,2,3, ... ,10 0.0,1.0,2.0, ... ,9.0 1,4,7,10 10,9,8, ... ,1 10,7,4,1 Linearly spaced vector of n=7 points Reverse Set all values to same scalar value
reverse(a)
a[::-1]
or
a.fill(3), a[:] = 3
Concatenation (vectors)
IDL [a,a] Python Description
or rebin(a,2,size(a))
[indgen(3)+1,a]
Repeating
IDL Python concatenate((a,a)) Description
or a.repeat(a) or
a.repeat(3)
1 2 3, 1 2 3 1 1 1, 2 2 2, 3 3 3 1, 2 2, 3 3 3
4 of 13
2/4/2014 2:52 PM
http://mathesaurus.sourceforge.net/idl-numpy.html
v,i = a.max(0),a.argmax(0)
Vector multiplication
IDL Python a*a crossp(u,v) dot(u,v) Description
Multiply two vectors Vector cross product, $u \times v$ Vector dot product, $u \cdot v$
Matrices
IDL a = [[2,3],[4,5]] Python a = array([[2,3],[4,5]]) Description
Define a matrix
Concatenate matrices into one vector concatenate((r_[1:5],r_[1:5])).reshape(2,-1) Bind rows (from vectors)
concatenate((a,b), axis=None) vstack((r_[1:5],r_[1:5]))
Array creation
IDL dblarr(3,5) intarr(3,5) dblarr(3,5)+1 intarr(3,5)+9 identity(3) diag_matrix([4,5,6]) identity(3) diag((4,5,6)) a = empty((3,3)) Python zeros((3,5),Float) zeros((3,5)) ones((3,5),Float) Description
0 filled array 0 filled array of integers 1 filled array Any number filled array Identity matrix Diagonal Empty array
5 of 13
2/4/2014 2:52 PM
http://mathesaurus.sourceforge.net/idl-numpy.html
a.flatten()
or
a.flatten(1)
Flatten to vector (by rows, like comics) Flatten to vector (by columns)
Copy of a
Element 2,3 (row,col) First row First column Array as indices All, except first row Last two rows Strides: Every other row Third in last dimension (axis) Remove one column Diagonal
Assignment
IDL Python a[:,0] = 99 a[:,0] = array([99,98,97]) a>90 (a>90).choose(a,90) a.clip(min=None, max=90) a < 2 > 5 a.clip(min=2, max=5) Description
Clipping: Replace all elements over 90 Clip upper and lower values
or linalg.inv(a) or
linalg.det(a) linalg.pinv(a) norm(a)
hqr(elmhes(a))
linalg.eig(a)[0]
6 of 13
2/4/2014 2:52 PM
http://mathesaurus.sourceforge.net/idl-numpy.html
svdc,A,w,U,V
Sum
IDL total(a,2) total(a,1) total(a) Python a.sum(axis=0) a.sum(axis=1) a.sum() a.trace(offset=0) a.cumsum(axis=0) Description
Sum of each column Sum of each row Sum of all elements Sum along diagonal Cumulative sum (columns)
Sorting
IDL Python a = array([[4,3,2],[2,8,6], [1,4,7]]) a.ravel().sort() sort(a) a.sort(axis=0) a.sort(axis=1) a[a[:,0].argsort(),] a.ravel().argsort() a.argsort(axis=0) a.argsort(axis=1) Description
Example data Flat and sorted Sort each column Sort each row Sort rows (by first row) Sort, return indices Sort each column, return indices Sort each row, return indices
or
or msort(a)
max in each column max in each row max in array pairwise max max-to-min range
Matrix manipulation
IDL reverse(a) reverse(a,2) rotate(a,1) Python Description
Flip left-right Flip up-down Rotate 90 degrees Repeat matrix: [ a a a ; a a a ] Triangular, upper Triangular, lower
7 of 13
2/4/2014 2:52 PM
http://mathesaurus.sourceforge.net/idl-numpy.html
Equivalents to "size"
IDL size(a) s=size(a) & s[1] n_elements(a) Python Description
Matrix dimensions Number of columns Number of elements Number of dimensions Number of bytes used in memory
or multiply(a,b) or or
or b
## a
matrixmultiply(a,b) inner(a,b)
transpose(a) # b
a # b
outer(a,b) kron(a,b)
cramer(a,b)
linalg.solve(a,b)
vdot(a,b) cross(a,b)
Elementwise operations Matrix product (dot product) Inner matrix vector multiplication $a\cdot b$ Outer product Kronecker product Left matrix division, $b^{-1} {\cdot}a$ \newline (solve linear equations) Vector dot product Cross product
Non-zero elements, indices Non-zero elements, array indices Vector of non-zero values Condition, indices Return values Zero out elements above 5.5 Replace values
or a
* (a>5.5)
Multi-way arrays
IDL Python a = array([[[1,2],[1,2]], [[3,4],[3,4]]]) a[0,...] Description
8 of 13
2/4/2014 2:52 PM
http://mathesaurus.sourceforge.net/idl-numpy.html
IDL read()
Description
Reading from a file (2d) Reading from a file (2d) Reading fram a CSV file (2d) Writing to a file (2d) Writing to a file (1d) Reading from a file (1d)
read() x =
f = load("data.txt") f = load('data.csv',
read_ascii(data_start=1,delimiter=';') delimiter=';') save('data.csv', f, fmt='%.6f', delimiter=';') f.tofile(file='data.csv', format='%.6f', sep=';') f = fromfile(file='data.csv', sep=';')
1d line plot 2d scatter plot Two graphs in one plot Overplotting: Add new plots to current subplots Plotting symbols and color
Turn on grid lines 1:1 aspect ratio Set axes manually Axis labels and titles
Insert text
Log plots
IDL plot, x,y, /YLOG plot, x,y, Python Description
plot_oo, x,y
9 of 13
2/4/2014 2:52 PM
http://mathesaurus.sourceforge.net/idl-numpy.html
Filled plot
Functions
IDL Python x = arrayrange(0,40,.5) y = sin(x/3) - cos(x/5) plot(x,y, 'o') Description
Polar plots
IDL Python theta = arange(0,2*pi,0.001) r = sin(2*theta) polar(theta, rho) Description
Histogram plots
IDL plot, histogram(randomn(5,1000)) Python Description
Contour plot
10 of 13
2/4/2014 2:52 PM
http://mathesaurus.sourceforge.net/idl-numpy.html
IDL
Description
PostScript
Create sets
Set unique
Set union Set intersection Set difference Set exclusion True for set member
Statistics
11 of 13 2/4/2014 2:52 PM
http://mathesaurus.sourceforge.net/idl-numpy.html
IDL mean(a)
Description
Average
median(a) stddev(a)
variance(a) correlate(x,y)
Differential equations
IDL Python diff(x, n=1, axis=0) Description
Fourier analysis
IDL fft(a) fft(a),/inverse convol() Python Description
or ifft(a) or
fft(a) convolve(x,y)
Programming
IDL Python Description
12 of 13
2/4/2014 2:52 PM
http://mathesaurus.sourceforge.net/idl-numpy.html
.idlbatch ;
Script file extension Comment symbol (rest of line) Import library functions Eval
Loops
IDL for k=1,5 do print,k for k=1,5 do begin $ print, i &$ print, i*2 &$ end Python for i in range(1,6): print(i) for i in range(1,6): print(i) print(i*2) Description
Conditionals
IDL if 1 gt 0 then a=100 if 1 gt 0 then a=100 else a=0 a>0?a:0 Python if 1>0: a=100 Description
Debugging
IDL help print, a print a Python Description
cd,'foo
or sd,'foo
spawn,'notepad'
List files in directory List script files in directory Displays the current working directory Change working directory Invoke a System Command
Time-stamp: "2007-11-09T16:46:36 vidar" 2006 Vidar Bronken Gundersen, /mathesaurus.sf.net Permission is granted to copy, distribute and/or modify this document as long as the above attribution is retained.
13 of 13
2/4/2014 2:52 PM