Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Tensorflow tf.split()列表索引超出范围?_Tensorflow - Fatal编程技术网

Tensorflow tf.split()列表索引超出范围?

Tensorflow tf.split()列表索引超出范围?,tensorflow,Tensorflow,以下是代码: a = tf.constant([1,2,3,4]) b = tf.constant([4]) c = tf.split(a, tf.squeeze(b)) 然后,结果证明是错误的: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/jeff/anaconda2/lib/python2.7/site-packages/tensorfl

以下是代码:

a = tf.constant([1,2,3,4])
b = tf.constant([4])
c = tf.split(a, tf.squeeze(b))
然后,结果证明是错误的:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/jeff/anaconda2/lib/python2.7/site-packages/tensorflow/python/ops/array_ops.py", line 1203, in split
    num = size_splits_shape.dims[0]
IndexError: list index out of range
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
文件“/home/jeff/anaconda2/lib/python2.7/site packages/tensorflow/python/ops/array_ops.py”,第1203行,拆分
num=大小分割形状。dims[0]
索引器:列表索引超出范围
但为什么呢?

陈述

若num_或size_splits是张量,则size_将拆分,然后将值拆分为len(size_splits)段。第i个工件的形状与该值的大小相同,但沿尺寸轴的大小为大小_splits[i]

请注意,
size\u拆分
需要可滑动

但是,当您挤压(b)时,因为在您的示例中它只有一个元素,所以它返回一个没有维度的标量。无法切片标量:

b_ = tf.squeeze(b)
b_[0] # error

这就是你的错误。

谢谢你的回答,但是现在如何将a拆分为4段呢?
tf.split(a,4)
,而不将数字包装在张量中。