https://blog.csdn.net/hejunqing14/article/details/71773926
https://blog.csdn.net/yjt1325/article/details/79758602
tensorflow學習的小白一枚。今天看到tensorflow中矩陣的乘法,看到有帖子說tensorflow中向量不能與矩陣直接相乘,不然會出錯。我就覺得很奇怪,tensorflow這麼流行的庫怎麼會出現這種弱智的問題呢?然後看了幾個帖子,怎麼解決這個問題的,看了半天,覺得太複雜了,並且他們寫錯了。其實tensorflow可以直接進行向量和矩陣的乘法。舉個例子
import tensorflow as tf
a = tf.constant([[1,2]]) #注意寫兩個中括號哦!
b = tf.constant([[5,6],[7,8]])
c = tf.matmul(a, b)
with tf.Session() as sess:
print(sess.run(c))
print(c)
小白一枚,希望對親們有幫助,歡迎交流和點贊,謝謝各位大大