[Python][numpy] numpy で行列計算

転置行列 (transpose)

a = numpy.arange(0, 6).reshape(2, 3) # 2x3 行列
print "arange(0, 6).reshapre(2, 3):"
print a

print "transpose():"
print a.transpose() # 転置行列 (transpose)

arange(0, 6).reshapre(2, 3):
[[0 1 2]
[3 4 5]]
transpose():
[[0 3]
[1 4]
[2 5]]



逆行列 (inverse)

a = numpy.arange(0, 4).reshape(2, 2) # 2x2 行列
print "arange(0, 4).reshapre(2, 2):"
print a

print "linalg.inv(a):"
print numpy.linalg.inv(a) # 逆行列 (inverse)

arange(0, 4).reshapre(2, 2):
[[0 1]
[2 3]]
linalg.inv(a):
[[-1.5 0.5]
[ 1. 0. ]]