My First Converted Jupyter notebook

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)
[[-0.0269058   0.39160873  0.17928672]
 [ 0.24797966 -0.39697382 -0.35499573]
 [ 0.30967847  0.32730359  0.30842749]
 [ 0.1528266   0.49989816  0.34428994]
 [ 0.29634302 -0.21905434  0.18902373]
 [-0.34851145 -0.12763465  0.26871769]
 [-0.3859855  -0.26051812  0.16394675]
 [ 0.03022932 -0.00579362 -0.55509157]
 [-0.29696686 -0.37009246 -0.39711054]
 [ 0.02131254  0.16125654 -0.14649449]]

links

social