Cheat Sheets and References
Linux command reference: http://files.fosswire.com/2007/08/fwunixref.pdf
Python for Matlab users: http://wiki.scipy.org/NumPy_for_Matlab_Users, http://mathesaurus.sourceforge.net/matlab-numpy.html
Show values in python
print "Hello world"
Hello world
mystr = "Hello world"
print mystr
Hello world
a = 5
b = 3
print (a+b)
8
Loops and arrays
Note ':' and indentation
for i in range(0,10,1): print i
0 1 2 3 4 5 6 7 8 9
for i in range(0,10):
if i > 5:
print i
6 7 8 9
numbers = range(0,10,1)
print numbers
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
Making simple plots
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 3*np.pi, 500)
plt.plot(x, np.sin(x**2))
plt.title('A simple chirp')
<matplotlib.text.Text at 0x7f0d23cc6110>
Cross-correlation of two 1-dimensional sequences
import numpy as np
np.correlate([1, 2, 3], [0, 1, 0.5])
array([ 3.5])
Estimate a covariance matrix
x = [-2.1, -1, 4.3]
y = [3, 1.1, 0.12]
print np.cov(x, y)
[[ 11.71 -4.286 ] [ -4.286 2.14413333]]
Compute the standard deviation
a = np.array([[1, 2], [3, 4]])
print "std:", np.std(a)
print "std across the rows:", np.std(a, axis=0)
print "std across the columns:", np.std(a, axis=1)
std: 1.11803398875 std across the rows: [ 1. 1.] std across the columns: [ 0.5 0.5]
Compute the arithmetic mean
a = np.array([[1, 2], [3, 4]])
print "mean:", np.mean(a)
print "mean across the rows:", np.mean(a, axis=0)
print "mean across the columns:", np.mean(a, axis=1)
mean: 2.5 mean across the rows: [ 2. 3.] mean across the columns: [ 1.5 3.5]