Write Blog Using Jupyter Notebooks and Pelican¶
Here is a quick reviev on how to write blog using Jupyter Notebook and python module pelican-jupyter. Not so much to write about, pelican-jupyter's docs are great. They may be read here: https://github.com/danielfrg/pelican-jupyter.
In [8]:
import numpy as np
# Rule 1
a = np.arange(3)
M = np.ones((2, 3))
#Rule 1 & 2
a = np.arange(3).reshape((3, 1))
b = np.arange(3) # [0 1 2]
"""
a is:
[[0]
[1]
[2]]
"""
a + b
# array([[0, 1, 2], [1, 2, 3], [2, 3, 4]])
#Example 3
#Rule 3
M = np.ones((3, 2))
a = np.arange(3)
shp_M = (3, 2)
shp_a = (3,)
#rule 1 pad the shape of a with ones at its leading side: a.shape -> (1, 3)
# Example 3 workaround
# reshaping the array with right side padding
M=np.ones((3, 2))
a=np.arange(3)
b=a[:,np.newaxis]
# shape of a, a.shape>>> (3,)
# shape of b, b.shape >>> (3,1)
# Practical broadcasting
## 1. Centering an array: compute mean across first axis
X = np.random.random((10, 3))
Xmean = X.mean(0)
# array([ 0.53514715, 0.66567217, 0.44385899])
Xcentered = X -Xmean
print(Xcentered)