tf.matmul为矩阵相乘,tf.multiply为矩阵中对应元素各自相乘
import numpy as np
import pandas as pd
from pandas import Series,DataFrame
import matplotlib.pyplot as plt
import tensorflow as tf
#tf.matmul为矩阵相乘,tf.multiply为矩阵中对应元素各自相乘
a = tf.constant([1,2,3,4,5,6],shape = [3,2])
b = tf.constant([7,8,9,10,11,12],shape = [2,3])
c = tf.matmul(a,b)
d = tf.multiply(a,a)
init = tf.global_variables_initializer()
with tf.Session() as sess:
sess.run(init)
print(sess.run(a))
print('------')
print(sess.run(b))
print('------')
print(sess.run(c))
print('------')
print(sess.run(d))
[[1 2]
[3 4]
[5 6]]
------
[[ 7 8 9]
[10 11 12]]
------
[[ 27 30 33]
[ 61 68 75]
[ 95 106 117]]
------
[[ 1 4]
[ 9 16]
[25 36]]
如果你已经来到这里,不妨关注如下公众号一起探索这个奇妙世界: