a = numpy.zeros((3, 4)) # 3x4 行列 print "zeros((3, 4)):" print a
zeros((3, 4)): [[ 0. 0. 0. 0.] [ 0. 0. 0. 0.] [ 0. 0. 0. 0.]]
すべて 1 の行列
a = numpy.ones((3, 4)) # 3x4 行列 print "ones((3, 4)):" print a
ones((3, 4)): [[ 1. 1. 1. 1.] [ 1. 1. 1. 1.] [ 1. 1. 1. 1.]]
単位行列
i = numpy.identity(3) # 3x3 単位行列 (identity matirx) print "identity(3):" print i
identity(3): [[ 1. 0. 0.] [ 0. 1. 0.] [ 0. 0. 1.]]
要素を指定して行列生成
a = numpy.array([0, 2, 3, 4, 6, 8]).reshape(2, 3) print "array([0, 2, 3, 4, 6, 8]).reshape(2, 3):" print a
array([0, 2, 3, 4, 6, 8]).reshape(2, 3): [[0 2 3] [4 6 8]]
特定の対角のみ 1 にする行列
a = numpy.eye(3) print "eye(3):" print a a = numpy.eye(3, k=1) print "eye(3, k=1):" print a
eye(3): [[ 1. 0. 0.] [ 0. 1. 0.] [ 0. 0. 1.]] eye(3, k=1): [[ 0. 1. 0.] [ 0. 0. 1.] [ 0. 0. 0.]]
0 件のコメント:
コメントを投稿