1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

各列が同じ値の2次元配列を作りたい

Last updated at Posted at 2023-08-12

各列が同じ値の2次元配列を作りたい

pythonのモジュールであるnumpyを使いだしたので備忘録に.

行をコピーする

以下のコードで同じ列の値が等しい配列が生成できます.

x = np.arange(-3.0,3.0,0.1) #-3から3まで0.1間隔で増える
x_copy = np.tile(x, (2,1)) #1行目を2回コピー

(2,1)を(5,1)に変える等でコピーする数を変えることができます.

x = np.arange(-3.0,3.0,0.1) #-3から3まで0.1間隔で増える
x_copy = np.tile(x, (5,1)) #1行目を5回コピー

当然だがコピーのところを(1,1)と指定したとしても行列のサイズは元と同じとは限らないことに注意.

その他のnumpyの機能

  • 同じ形状の配列を生成
x = np.array([[1,2],[3,4]])
x_like = np.zeros_like(x) #同じ形状のゼロ配列
1
0
0

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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?