【python備忘録】numpyで縦ベクトルを作る

#Python
import numpy as np

np.arange(0,6)
# array([0, 1, 2, 3, 4, 5])

np.arange(0,6)[:, np.newaxis]
# array([[0],
#       [1],
#       [2],
#       [3],
#       [4],
#       [5]])

np.arange(0,6) + np.arange(0,6)[:, npnewaxis]
#array([[ 0,  1,  2,  3,  4,  5],
#       [10, 11, 12, 13, 14, 15],
#       [20, 21, 22, 23, 24, 25],
#       [30, 31, 32, 33, 34, 35],
#       [40, 41, 42, 43, 44, 45],
#       [50, 51, 52, 53, 54, 55]])

コメントを残す