将张量转换为 int32 类型

版权声明:本文为博主原创文章,转载请附上博文链接! https://blog.csdn.net/weixin_38314865/article/details/84751426

tf.to_int32函数:

tf.to_int32(
    x,
    name='ToInt32'
)

函数参数:

  • x:一个 Tensor 、SparseTensor、list或ndarray
  • name:操作的名称(可选)。

函数返回值:

tf.to_int32函数返回一个 Tensor 或 SparseTensor,与 x (类型为 int32)具有相同的形状。

例子:

import numpy as np
import tensorflow as tf

a = [[1,2,3], [2,3,4]]
b = np.array([[1,2,3], [2,3,4]])
c = tf.convert_to_tensor([[1,2,3], [2,3,4]])
d = tf.to_int32(a)
e = tf.to_int32(b)
f = tf.to_int32(c)
sess = tf.InteractiveSession()
print(sess.run(d))
print(sess.run(e))
print(sess.run(f))

猜你喜欢

转载自blog.csdn.net/weixin_38314865/article/details/84751426
今日推荐