TensorFlow矩陣向量運算

2021-08-15 05:36:45 字數 842 閱讀 7541

1 向量點乘

結果是乙個向量在另乙個向量方向上投影的長度,是乙個標量。

2 向量叉乘

結果是乙個和已有兩個向量都垂直的向量。

向量a = (x1,y1),b = (x2,y2)

a *b = x1*x2+y1*y2 =|a||b|cos

a叉乘b = x1 * y2 - x2 * y1=|a||b|sin

tensorflow

3. 矩陣乘

tf.matmul(a,b)//matrix_multiply== tf.tensordot(a,b,axie=1)

tf.tensordot()

功能:同numpy.tensordot,根據axis計算點乘。

輸入:axes=1或axes=[[1],[0]],即為矩陣乘。

tf.multiply(a,b) == a * b

tf.mul()是可以b』roadcast,

(3,2) * (2) = (3,2)*(1,2) = (3,2)

(3,2)*(3,1) = (3,2)

矩陣點成向量

(3,2) .* (2)

u=tf.reshape(np.arange(0,5),[3,2])

v=tf.variable(tf.random_uniform([2]))

mul=tf.reduce_sum(tf.mul(tf.cast(u,tf.float32),v),reduction_indices=1)

s=tf.session()

s.run(tf.initialize_all_variables())

print s.run(mul)

tensorflow中向量與矩陣相乘

tensorflow學習的小白一枚。今天看到tensorflow中矩陣的乘法,看到有帖子說tensorflow中向量不能與矩陣直接相乘,不然會出錯。我就覺得很奇怪,tensorflow這麼流行的庫怎麼會出現這種弱智的問題呢?然後看了幾個帖子,怎麼解決這個問題的,看了半天,覺得太複雜了,並且他們寫錯了...

TensorFlow2 0矩陣與向量的加減乘例項

1 矩陣加法使用 a np.ran程式設計客棧dom.random 3,3 b np.random.randint 0,9,3,3 ad tf.add a,b 2 矩陣乘法注意 tens程式設計客棧orflow 使用矩陣乘法都必須使用相同型別的資料,否則報錯。a np.random.random 5...

TensorFlow 矩陣計算

1 建立乙個張量矩陣,tensorflow 中使用常量建立函式,即 tf.constant 來建立乙個矩陣 tf.constant 1,2,3 shape 2,3 這行 建立了乙個2行3列的矩陣 2 建立隨機生成矩陣張量 tf.random normal shape,mean 0.0,stddev ...