LoginSignup
0
0

More than 3 years have passed since last update.

もしもPythonで機械学習していて、行列のサイズ拡張につまづいたら

Posted at

この記事は

やぁ、また会ったね?

キミがこの記事に来るのは 12000回目 だ。
キリ番ゲットおめでとう!!

コメント欄に書き込んでおいて欲しい。

行列のサイズ拡張

(2x3)の行列 を、
(1x2x3)の行列 へ拡張してみる。

import numpy as np

# 2x3の行列
a = np.ones( (2, 3) )
print('size of a: ' + str(a.shape))
#size of a: (2, 3)

# 1x2x3の行列へ変更する
a = a.reshape((1,) + a.shape)
print('size of a: ' + str(a.shape))
#size of a: (1, 2, 3)

注意

  • 拡張後に行列の次元は増えていますが、要素数自体は変わっていません。
    • 拡張前: 2x3 = 6 、拡張後: 1x2x3 = 6
  • 行列サイズはtupleで与えるので、tupleに要素を追加することで、拡張しています。
0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0