tf.pow, tf.math.pow 讲解

tf.pow, tf.math.pow 是一样的

这个操作为:x和y中的 对应元素 计算 x y x^{y} ,注意支持"广播方式(写这篇博客的初衷)"
返回的是一个tensor

tf.math.pow(
    x,
    y,
    name=None
)
sess=tf.Session()


x=tf.constant([[2,3],[4,5]])
y_1=2
res_1=tf.pow(x,y_1)
sess.run(res_1)
'''
输出
	array([[ 4,  9],
	       [16, 25]], dtype=int32)
'''



x=tf.constant([[2,3],[4,5]])
y_2=[2,3]
sess.run(tf.pow(x,y_2))
'''
输出 :
	array([[  4,  27],
	       [ 16, 125]], dtype=int32)
'''





x=tf.constant([[2,3],[4,5]])
y_3=[[2],[3]]
sess.run(tf.pow(x,y_3))
'''
输出:
	array([[  4,   9],
	       [ 64, 125]], dtype=int32)
'''


x=tf.constant([[2,3],[4,5]])
y_4=[[1,2],[3,2]]
sess.run(tf.pow(x,y_4))
'''
输出:
	array([[ 2,  9],
	       [64, 25]], dtype=int32)
'''

猜你喜欢

转载自blog.csdn.net/qq_32806793/article/details/85330321
pow
tf
今日推荐