読者です 読者をやめる 読者になる 読者になる

Pythonデータサイエンスクックブック

(2順目)

レシピ9.4

3項
np.repeat(arr,2)はarrの各要素の2個つづ繰り返す。 arr = [1,2,3]だったら np.repeat(arr,2)は2回リピートするので [1,1,2,2,3,3]となる。 np.til((a,b),3)は(a,b)タプルをタイルのように3回敷き詰めていくので [a,b,a,b,a,b]となる

P0配列は最終次のようになる。

[[ 0.   0. ]
[ 0.  -0.1]
[ 0.1  0. ]
[ 0.1 -0.1]
[ 0.2  0. ]
[ 0.2 -0.1]
[ 0.3  0. ]
[ 0.3 -0.1]
[ 0.4  0. ]
[ 0.4 -0.1]
[ 0.5  0. ]
[ 0.5 -0.1]
[ 0.6  0. ]
[ 0.6 -0.1]
[ 0.7  0. ]
[ 0.7 -0.1]
[ 0.8  0. ]
[ 0.8 -0.1]
[ 0.9  0. ]
[ 0.9 -0.1]]

4項
配列Aは

[[ 0.  1.  1.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.   0.  0.]
[ 0.  0.  1.  1.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.   0.  0.]
[ 0.  0.  0.  1.  1.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.   0.  0.]
[ 0.  0.  0.  0.  1.  1.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.   0.  0.]
[ 0.  0.  0.  0.  0.  1.  1.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.   0.  0.]
[ 0.  0.  0.  0.  0.  0.  1.  1.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.   0.  0.]
[ 0.  0.  0.  0.  0.  0.  0.  1.  1.  0.  0.  0.  0.  0.  0.  0.  0.  0.   0.  0.]
[ 0.  0.  0.  0.  0.  0.  0.  0.  1.  1.  0.  0.  0.  0.  0.  0.  0.  0.   0.  0.]
[ 0.  0.  0.  0.  0.  0.  0.  0.  0.  1.  1.  0.  0.  0.  0.  0.  0.  0.   0.  0.]
[ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  1.  1.  0.  0.  0.  0.  0.  0.   0.  0.]
[ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  1.  1.  0.  0.  0.  0.  0.   0.  0.]
[ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  1.  1.  0.  0.  0.  0.   0.  0.]
[ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  1.  1.  0.  0.  0.   0.  0.]
[ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  1.  1.  0.  0.   0.  0.]
[ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  1.  1.  0.   0.  0.]
[ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  1.  1.   0.  0.]
[ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  1.   1.  0.]
[ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.   1.  1.]
[ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.   0.  1.]
[ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.   0.  0.]]

となる。
eyeは単位行列を返す関数であるが3番目の引数が対角線上からのオフセット数を表す
プラス値を入れれば右にずれ、マイナス値を入れれば右にずれる
5項
L配列は20行20列

[[ 0. 0.1 0.1 0. 0. 0. 0.   0. 0. 0. 0. 0. 0. 0.   0. 0. 0. 0. 0. 0. ]
[ 0. 0. 0.14142136  0.1 0. 0. 0.   0. 0. 0. 0. 0. 0. 0.   0. 0. 0. 0. 0. 0. ]
[ 0. 0. 0. 0.1 0.1 0. 0.   0. 0. 0. 0. 0. 0. 0.   0. 0. 0. 0. 0. 0. ]
[ 0. 0. 0. 0. 0.14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 0.   0. 0. 0. 0. 0. 0. 0.   0. 0. 0. 0. 0. 0.1       ]
[ 0. 0. 0. 0. 0. 0. 0.   0. 0. 0. 0. 0. 0. 0.   0. 0. 0. 0. 0. 0. ]]

9項
f:id:bitop:20160410081806p:plain
13項
f:id:bitop:20160410082148p:plain