【numpy】行列操作【その1】

numpyの行列操作で面白い行列の作り方を知ったので書く.

a = np.arange(1,11)
b = np.arange(0,10)
#b: [0,1,2,3,4,5,6,7,8,9]
c = b[:,np.newaxis]
#c: 
#[[0]
# [1]
# [2]
# [3]
# [4]
# [5]
# [6]
# [7]
# [8]
# [9]]
d = a + c
#[[ 1  2  3  4  5  6  7  8  9 10]
# [ 2  3  4  5  6  7  8  9 10 11]
# [ 3  4  5  6  7  8  9 10 11 12]
# [ 4  5  6  7  8  9 10 11 12 13]
# [ 5  6  7  8  9 10 11 12 13 14]
# [ 6  7  8  9 10 11 12 13 14 15]
# [ 7  8  9 10 11 12 13 14 15 16]
# [ 8  9 10 11 12 13 14 15 16 17]
# [ 9 10 11 12 13 14 15 16 17 18]
# [10 11 12 13 14 15 16 17 18 19]]
X = 1./ d
# 1.をdの要素で割った形

【参考】
http://scikit-learn.org/stable/auto_examples/linear_model/plot_ridge_path.html#sphx-glr-auto-examples-linear-model-plot-ridge-path-py