LoginSignup
2
0

More than 5 years have passed since last update.

“np.transepose”で、行列が転置されない場合の対処法

Posted at

Pythonを学習している中で、陥ったミスをまとめています。
初心者向けですので、あたりまえだと思う方はスキップしてください。

Pythonで、1行N列やN行1列の行列を転置したいときに、
“np.transpose”を用いても、できないときがありました。

そういう時は、“.reshape”を用いてください。

例を以下に示します。
1行N列の行列を定義した後、“np.transpose”で転置した場合と
“.reshape”で形を変えた場合を示します。

>> import numpy as np
>> N = 10
>> a = np.arange(N)
>> print(a)
array[0 1 2 ・・・ 9]
>> b = np.transpose(a)
>> print(b)
array[0 1 2 ・・・ 9]
>> c = a.reshape(N,1)
>> print(c)
[[0]
 [1]
 [2]
 [3]
 [4]
 [5]
 [6]
 [7]
 [8]
 [9]
2
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
2
0