diff --git a/README.md b/README.md index 8b4e165..0453457 100644 --- a/README.md +++ b/README.md @@ -127,7 +127,7 @@ ###// Useful scripts and snippets [[back to top](#a-collection-of-useful-scripts-tutorials-and-other-python-related-things)] -- [IPython magic function %watermark](http://nbviewer.ipython.org/github/rasbt/python_reference/blob/master/ipython_magic/watermark.ipynb) - for printing date- and time-stamps and various system info +- [watermark](https://github.com/rasbt/watermark) - An IPython magic extension for printing date and time stamps, version numbers, and hardware information. - [Shell script](./useful_scripts/prepend_python_shebang.sh) for prepending Python-shebangs to .py files. diff --git a/ipython_magic/README.md b/ipython_magic/README.md new file mode 100644 index 0000000..fb167a8 --- /dev/null +++ b/ipython_magic/README.md @@ -0,0 +1,8 @@ +watermark +========= + +An IPython magic extension for printing date and time stamps, version numbers, and hardware information + + + +**watermark is now located and maintained in a separate GitHub repository:** [https://github.com/rasbt/watermark](https://github.com/rasbt/watermark) \ No newline at end of file diff --git a/ipython_magic/images/watermark_ex1.png b/ipython_magic/images/watermark_ex1.png new file mode 100644 index 0000000..6e95b03 Binary files /dev/null and b/ipython_magic/images/watermark_ex1.png differ diff --git a/ipython_magic/watermark.ipynb b/ipython_magic/watermark.ipynb index 3c2433e..d88d6b8 100644 --- a/ipython_magic/watermark.ipynb +++ b/ipython_magic/watermark.ipynb @@ -1,7 +1,7 @@ { "metadata": { "name": "", - "signature": "sha256:ae521d31a2ed8eb2f249825915f64611628365cb0ced53ef18be691238c0018e" + "signature": "sha256:968e6f47972d4ab9e2ef4eef6906343257267ccf094fcae08da24fec3647743d" }, "nbformat": 3, "nbformat_minor": 0, @@ -23,6 +23,13 @@ "
+ |
Task |
-
- MATLAB/Octave + |
+ MATLAB/Octave |
-
- Python + |
+ Python NumPy |
-
- R + |
+ R |
-
- Julia + |
+ Julia |
- + |
Task |
+ |
CREATING MATRICES |
||||||||||
+ |
Creating
Matrices |
-
- M> + |
+ M>
A = [1 2 3; 4 5 6; 7 8 9] |
-
- P> + |
+ P>
A = np.array([ [1,2,3], [4,5,6], [7,8,9] ]) |
-
- R> + |
+ R>
A = matrix(c(1,2,3,4,5,6,7,8,9),nrow=3,byrow=T) |
-
- J> + |
+ J>
A=[1 2 3; 4 5 6; 7 8 9] |
- + |
Creating
Matrices |
+ |
Creating an 1D column vector |
-
- M> + |
+ M>
a = [1; 2; 3] |
-
- P> - a - = + |
+ P> + a + = np.array([1,2,3]).reshape(1,3) -
|
-
- R> + |
+ R>
a = matrix(c(1,2,3), nrow=3, byrow=T) |
-
- J> + |
+ J>
a=[1; 2; 3] |
- + |
Creating an 1D column vector |
+ |
Creating
an |
-
- M> + |
+ M>
b = [1 2 3] |
-
- P> + |
+ P>
b = np.array([1,2,3]) #
+ #
note that numpy doesn't have P>
- b.shape (3,) P>
+ b.shape (3,) |
-
- R> + |
+ R>
b = matrix(c(1,2,3), ncol=3) |
-
- J> + |
+ J>
b=[1 2 3] |
- + |
Creating
an |
+ |
Creating
a |
-
- M> + |
+ M>
rand(3,2) |
-
- P> + |
+ P>
np.random.rand(3,2) |
-
- R> + |
+ R>
matrix(runif(3*2), ncol=2) |
-
- J> + |
+ J>
rand(3,2) |
- + |
Creating
a |
+ |
Creating
a |
-
- M> + |
+ M>
zeros(3,2) |
-
- P> + |
+ P>
np.zeros((3,2)) |
-
- R> + |
+ R>
mat.or.vec(3, 2) |
-
- J> + |
+ J>
zeros(3,2) |
- + |
Creating
a |
+ |
Creating
an |
-
- M> + |
+ M>
ones(3,2) |
-
- P> + |
+ P>
np.ones((3,2)) |
-
- R>
- matrix(1L,
- 3, 2) |
+ R>
+ mat.or.vec(3, 2) + 1 |
-
- J> + |
+ J>
ones(3,2) |
- + |
Creating
an |
+ |
Creating
an |
-
- M> + |
+ M>
eye(3) |
-
- P> + |
+ P>
np.eye(3) |
-
- R> + |
+ R>
diag(3) |
-
- J> + |
+ J>
eye(3) |
- + |
Creating
an |
+ |
Creating
a |
-
- M> + |
+ M>
a = [1 2 3] |
-
- P> + |
+ P>
a = np.array([1,2,3]) |
-
- R> + |
+ R>
diag(1:3) |
-
- J> + |
+ J>
a=[1, 2, 3] |
- + |
Creating
a |
+ |
ACCESSING MATRIX ELEMENTS |
||||||||||
+ |
Getting
the dimension |
-
- M> + |
+ M>
A = [1 2 3; 4 5 6] |
-
- P> + |
+ P>
A = np.array([ [1,2,3], [4,5,6] ]) |
-
- R> + |
+ R>
A = matrix(1:6,nrow=2,byrow=T) R>
+ R>
dim(A) |
-
- J> + |
+ J>
A=[1 2 3; 4 5 6] |
- + |
Getting
the dimension |
+ |
Selecting rows |
-
- M> + |
+ M>
A = [1 2 3; 4 5 6; 7 8 9] |
-
- P> + |
+ P>
A = np.array([ [1,2,3], [4,5,6], [7,8,9] ]) |
-
- R> + |
+ R>
A = matrix(1:9,nrow=3,byrow=T)
|
-
- J> + |
+ J>
A=[1 2 3; 4 5 6; 7 8 9]; |
- + |
Selecting rows |
+ |
Selecting columns |
-
- M> + |
+ M>
A = [1 2 3; 4 5 6; 7 8 9] |
-
- P> + |
+ P>
A = np.array([ [1,2,3], [4,5,6], [7,8,9] ]) |
-
- R> + |
+ R>
A = matrix(1:9,nrow=3,byrow=T)
|
-
- J> + |
+ J>
A=[1 2 3; 4 5 6; 7 8 9]; |
- + |
Selecting columns |
+ |
Extracting
rows and columns by criteria |
-
- M> + |
+ M>
A = [1 2 3; 4 5 9; 7 8 9] |
-
- P> + |
+ P>
A = np.array([ [1,2,3], [4,5,9], [7,8,9]]) |
-
- R>
- A = matrix(1:9,nrow=3,byrow=T)
|
+ R>
+ A = matrix(1:9,nrow=3,byrow=T)
[1]
+ 9
|
-
- J> + |
+ J>
A=[1 2 3; 4 5 9; 7 8 9] |
- + |
Extracting
rows and columns by criteria |
+ |
Accessing
elements |
-
- M> + |
+ M>
A = [1 2 3; 4 5 6; 7 8 9] |
-
- P> + |
+ P>
A = np.array([ [1,2,3], [4,5,6], [7,8,9] ]) |
-
- R> + |
+ R>
A = matrix(c(1,2,3,4,5,9,7,8,9),nrow=3,byrow=T)
|
-
- J> + |
+ J>
A=[1 2 3; 4 5 6; 7 8 9]; |
- + |
Accessing
elements |
+ |
MANIPULATING SHAPE AND DIMENSIONS |
||||||||||
- Converting |
-
- M> - A = [1 2 3; 4 5 6; 7 8 9] -M> - A(:) -ans - = - -1
- |
-
- P> - A = np.array([[1,2,3],[4,5,6],[7,8,9]]) -P> - A.flatten(1) -array([1, - 4, 7, 2, 5, 8, 3, 6, 9]) -
|
-
- R> - A = matrix(1:9,nrow=3,byrow=T) -
R> - as.vector(A) -
[1] - 1 4 7 2 5 8 3 6 9 -
|
-
- J> - A=[1 2 3; 4 5 6; 7 8 9] -J> - vec(A) -9-element - Array{Int64,1}: -1 |
-
- Converting |
- ||||||
+ |
Converting |
-
- M> + |
+ M>
b = [1 2 3]
|
-
- P> + |
+ P>
b = np.array([1, 2, 3]) |
-
- R> + |
+ R>
b = matrix(c(1,2,3), ncol=3) |
-
- J> + |
+ J>
b=vec([1 2 3]) |
- + |
Converting |
+ |
Reshaping
Matrices |
-
- M> + |
+ M>
A = [1 2 3; 4 5 6; 7 8 9] |
-
- P> + |
+ P>
A = np.array([[1,2,3],[4,5,6],[7,8,9]]) P>
+ P>
B = A.reshape(1, total_elements) |
-
- R> + |
+ R>
A = matrix(1:9,nrow=3,byrow=T)
|
-
- J> + |
+ J>
A=[1 2 3; 4 5 6; 7 8 9] |
- + |
Reshaping
Matrices |
+ |
Concatenating matrices |
-
- M> + |
+ M>
A = [1 2 3; 4 5 6] |
-
- P> + |
+ P>
A = np.array([[1, 2, 3], [4, 5, 6]]) |
-
- R> + |
+ R>
A = matrix(1:6,nrow=2,byrow=T) |
-
- J> + |
+ J>
A=[1 2 3; 4 5 6]; |
- + |
Concatenating matrices |
+ |
Stacking |
-
- M> + |
+ M>
a = [1 2 3] |
-
- P> + |
+ P>
a = np.array([1,2,3]) |
-
- R> + |
+ R>
a = matrix(1:3, ncol=3) |
-
- J> + |
+ J>
a=[1 2 3]; |
- + |
Stacking |
+ |
BASIC MATRIX OPERATIONS |
||||||||||
+ |
Matrix-scalar |
-
- M> A + |
+ M> A
= [1 2 3; 4 5 6; 7 8 9] |
-
- P> + |
+ P>
A = np.array([ [1,2,3], [4,5,6], [7,8,9] ]) #
+ #
Note that NumPy was optimized for |
-
- R> + |
+ R>
A = matrix(1:9, nrow=3, byrow=T) R>
+ R>
A + 2 |
-
- J> + |
+ J>
A=[1 2 3; 4 5 6; 7 8 9]; |
- + |
Matrix-scalar |
+ |
Matrix-matrix |
-
- M> A + |
+ M> A
= [1 2 3; 4 5 6; 7 8 9] |
-
- P> + |
+ P>
A = np.array([ [1,2,3], [4,5,6], [7,8,9] ]) |
-
- R> + |
+ R>
A = matrix(1:9, nrow=3, byrow=T) |
-
- J> + |
+ J>
A=[1 2 3; 4 5 6; 7 8 9]; |
- + |
Matrix-matrix |
+ |
Matrix-vector |
-
- M> + |
+ M>
A = [1 2 3; 4 5 6; 7 8 9] |
-
- P> + |
+ P>
A = np.array([ [1,2,3], [4,5,6], [7,8,9] ]) |
-
- R> + |
+ R>
A = matrix(1:9, ncol=3) |
-
- J> + |
+ J>
A=[1 2 3; 4 5 6; 7 8 9]; |
- + |
Matrix-vector |
+ |
Element-wise |
-
- M> A + |
+ M> A
= [1 2 3; 4 5 6; 7 8 9] |
-
- P> + |
+ P>
A = np.array([ [1,2,3], [4,5,6], [7,8,9] ]) #
+ #
Note that NumPy was optimized for |
-
- R> + |
+ R>
A = matrix(1:9, nrow=3, byrow=T)
|
-
- J> + |
+ J>
A=[1 2 3; 4 5 6; 7 8 9]; |
- + |
Element-wise |
+ |
Matrix
elements to power n |
-
- M> A + |
+ M> A
= [1 2 3; 4 5 6; 7 8 9] |
-
- P> + |
+ P>
A = np.array([ [1,2,3], [4,5,6], [7,8,9] ]) |
-
- R> + |
+ R>
A = matrix(1:9, nrow=3, byrow=T) |
-
- J> + |
+ J>
A=[1 2 3; 4 5 6; 7 8 9]; |
- + |
Matrix
elements to power n |
+ |
Matrix
to power n |
-
- M> A + |
+ M> A
= [1 2 3; 4 5 6; 7 8 9] |
-
- P> + |
+ P>
A = np.array([ [1,2,3], [4,5,6], [7,8,9] ]) |
-
- R> + |
+ R>
A = matrix(1:9, ncol=3) |
-
- J> + |
+ J>
A=[1 2 3; 4 5 6; 7 8 9]; |
- + |
Matrix
to power n |
+ |
Matrix transpose |
-
- M> A + |
+ M> A
= [1 2 3; 4 5 6; 7 8 9] |
-
- P> + |
+ P>
A = np.array([ [1,2,3], [4,5,6], [7,8,9] ]) |
-
- R> + |
+ R>
A = matrix(1:9, nrow=3, byrow=T)
|
-
- J> + |
+ J>
A=[1 2 3; 4 5 6; 7 8 9] |
- + |
Matrix transpose |
+ |
Determinant
of a matrix: |
-
- M> + |
+ M>
A = [6 1 1; 4 -2 5; 2 8 7] |
-
- P> A + |
+ P> A
= np.array([[6,1,1],[4,-2,5],[2,8,7]]) |
-
- R> + |
+ R>
A = matrix(c(6,1,1,4,-2,5,2,8,7), nrow=3, byrow=T) |
-
- J> + |
+ J>
A=[6 1 1; 4 -2 5; 2 8 7] |
- + |
Determinant
of a matrix: |
+ |
Inverse of a matrix |
-
- M> + |
+ M>
A = [4 7; 2 6] |
-
- P> + |
+ P>
A = np.array([[4, 7], [2, 6]]) |
-
- R> + |
+ R>
A = matrix(c(4,7,2,6), nrow=2, byrow=T) |
-
- J> + |
+ J>
A=[4 7; 2 6] |
- + |
Inverse of a matrix |
+ |
ADVANCED MATRIX OPERATIONS |
||||||||||
+ |
Calculating
the covariance matrix |
-
- M> + |
+ M>
x1 = [4.0000 4.2000 3.9000 4.3000 4.1000]’ |
-
- P> + |
+ P>
x1 = np.array([ 4, 4.2, 3.9, 4.3, 4.1]) |
-
- R> + |
+ R>
x1 = matrix(c(4, 4.2, 3.9, 4.3, 4.1), ncol=5) |
-
- J> + |
+ J>
x1=[4.0 4.2 3.9 4.3 4.1]'; |
- + |
Calculating
the covariance matrix |
+ |
Calculating |
-
- M> + |
+ M>
A = [3 1; 1 3] |
-
- P> + |
+ P>
A = np.array([[3, 1], [1, 3]]) |
-
- R> + |
+ R>
A = matrix(c(3,1,1,3), ncol=2) |
-
- J> + |
+ J>
A=[3 1; 1 3] |
- + |
Calculating |
+ |
Generating
a Gaussian dataset: |
-
- % + |
+ %
requires statistics toolbox package |
-
- P> + |
+ P>
mean = np.array([0,0]) |
-
- # + |
+ #
requires the ‘mass’ package |
-
- # + |
+ #
requires the Distributions package from
https://github.com/JuliaStats/Distributions.jl |
- + |
Generating
a Gaussian dataset: |