0
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 3 years have passed since last update.

numpyで行列の内積を求めてみた

Posted at

#行列の内積を求める
( a行 b列 )×( b行 c列 )=( a行 c列 )という計算になる。
スクリーンショット 2020-06-22 0.12.02.jpg

ではこの計算をNumpyでしてみるとどうなるのか
ソースコードは以下の通りです。
####サンプルコード

matrixInnerProduct.py
# 乱数を発生させて(5行3列)×(3行4列)
#                  = (5行4列)の行列を求める
import numpy as np

a = np.random.randint(0, 14, size=(5, 3))
b = np.random.randint(0, 14, size=(3, 4))
print(a)
print(b)

print("内積の計算結果:")
c = np.dot(a,b)
print(c)

####出力結果

Anser
[[ 4  4  5]
 [ 7  6  5]
 [ 9  6 13]
 [ 5  8  7]
 [ 4  9  4]]
[[ 3  1  3  2]
 [ 1  3  6 10]
 [13  2  4  2]]
内積の計算結果
[[ 81  26  56  58]
 [ 92  35  77  84]
 [202  53 115 104]
 [114  43  91 104]
 [ 73  39  82 106]]

#まとめ
数学式については何かと便利なPython
上手に使っていきたい

・ちなみに参考サイト
データサイエンス力を飛躍的に向上させるNumPy徹底入門

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