1.tf.size()的作用
返回输入张量的大小,注意不是 shape,而是元素个数,0 维张量,默认为 tf.int32 类型(下面的示例中可看到)
tf.size(input,
name=None,
out_type=tf.int32
)
参数:
input:张量或稀疏张量
name:可选参数,操作的名称
out_type:可选参数,操作的指定非量化数字输出类型,默认是 tf.int32 类型
返回:
out_type 数据类型的张量,默认是 tf.int32.
例子:
import tensorflow as tf
tens = tf.constant([[1, 2, 3], [1, 2, 3]])
print tens
sess = tf.Session()
print tf.size(tens)
print sess.run(tf.size(tens))
输出:
Tensor("Const:0", shape=(2, 3), dtype=int32)
Tensor("Size:0", shape=(), dtype=int32)
6