numpyのメモ.行列に要素が全て1の列ベクトルを挿入
>>>import numpy as np
>>>X = np.array([[1,2],[3,4],[5,6]])
>>>print X
[[1 2]
[3 4]
[5 6]]
>>>a = np.column_stack((np.ones((3,1)),X))
>>>print a
[[ 1. 1. 2.]
[ 1. 3. 4.]
[ 1. 5. 6.]]
>>>import numpy as np
>>>b = np.concatenate((np.ones((3,1)),X),axis=1)
>>>print b
[[ 1. 1. 2.]
[ 1. 3. 4.]
[ 1. 5. 6.]]
>>>import numpy as np
>>>c = np.hstack((np.ones((3,1)),X))
>>>print c
[[ 1. 1. 2.]
[ 1. 3. 4.]
[ 1. 5. 6.]]
コメント