tf.square

时间:2023-03-10 02:25:21
tf.square

tf.square

square(
x,
name=None
)

功能说明:

计算张量对应元素平方

参数列表:

参数名 必选 类型 说明
x 张量 是 half, float32, float64, int32, int64, complex64, complex128 其中一种类型
name string 运算名称

示例代码:

import tensorflow as tf
ini_x=[[1,2],[3,4],[5,6]]
x=tf.Variable(ini_x,dtype=tf.int32)
ini_op=tf.global_variables_initializer()
xx_op=tf.square(x)
with tf.Session() as sess:
sess.run(ini_op)
print(sess.run(xx_op)) [[ 1 4]
[ 9 16]
[25 36]]