尝试使用此代码生成包含一系列数字的扩展数组,但这会在行d = tf.tile(k, [m])
中引发错误
import tensorflow as tf
min_rating = tf.constant(0, tf.int64)
max_rating = tf.constant(12, tf.int64)
m = max_rating - min_rating + 1
k = tf.range(m, dtype=tf.int64)
d = tf.tile(k, [m])
with tf.Session() as sess:
a = sess.run([d])
print a
以下是错误日志:
d = tf.tile(k, [m])
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/gen_array_ops.py", line 3740, in tile
name=name)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/op_def_library.py", line 493, in apply_op
raise err
TypeError: List of Tensors when single Tensor expected
我找不到任何参考。 tf.range
是否返回张量序列?
答案 0 :(得分:1)
[m]
行中的 d = tf.tile(k, [m])
是错误所指的“张量列表”。我猜你用括号m
将multiples
tf.tile
参数作为1-D Tensor。事实证明,[m]
只是一个张量列表。您可能希望使用tf.reshape
制作1-D Tensor,即将错误行更改为:
d = tf.tile(k, tf.reshape(m, [1]))