tf.squared_difference
squared_difference( x, y, name=None )
功能說明:
計算張量 x、y 對應元素差平方
參數列表:
參數名 | 必選 | 類型 | 說明 |
---|---|---|---|
x | 是 | 張量 | 是 half, float32, float64, int32, int64, complex64, complex128 其中一種類型 |
y | 是 | 張量 | 是 half, float32, float64, int32, int64, complex64, complex128 其中一種類型 |
name | 否 | string | 運算名稱 |
s
import tensorflow as tf import numpy as np initial_x = [[1.,1.],[2.,2.]] x = tf.Variable(initial_x,dtype=tf.float32) initial_y=[[1.,2.],[4.,5.]] y=tf.Variable(initial_y,dtype=tf.float32) diff = tf.squared_difference(x,y) init_op = tf.global_variables_initializer() with tf.Session() as sess: sess.run(init_op) print (sess.run(diff))
[[0. 1.]
[4. 9.]]