Print语句说不是吗?

时间:2018-06-09 19:47:41

标签: python

老实说,这是一个非常奇怪的情况:

def next_feed():        
    print('This is the batch:',batch_query,' and this is the type:', type(batch_query)) # This returns "This is the batch: [3, 20, 11]  and this is the type: <class 'list'>"
    print(batch(batch_query)) # This throws the error

现在,它也可能是batch()中的错误:

def batch(inputs, max_sequence_length=None):
    """
    Args:
        inputs:
            list of sentences (integer lists)
        max_sequence_length:
            integer specifying how large should `max_time` dimension be.
            If None, maximum sequence length would be used

    Outputs:
        inputs_time_major:
            input sentences transformed into time-major matrix
            (shape [max_time, batch_size]) padded with 0s
        sequence_lengths:
            batch-sized list of integers specifying amount of active
            time steps in each input sequence
    """

    sequence_lengths = [len(seq) for seq in inputs]
    batch_size_ = len(inputs)

    if max_sequence_length is None:
        max_sequence_length = max(sequence_lengths)

    inputs_batch_major = np.zeros(shape=[batch_size_, max_sequence_length], dtype=np.int32)  # == PAD

    for i, seq in enumerate(inputs):
        for j, element in enumerate(seq):
            inputs_batch_major[i, j] = element

    # [batch_size, max_time] -> [max_time, batch_size]
    inputs_time_major = inputs_batch_major.swapaxes(0, 1)

    return inputs_time_major, sequence_lengths

但是,我不知道怎么会发生这种情况,也不会在错误上看到它(我的意思是如果在批处理时发生错误它会记录它,对吗?)

  

文件“xxxxxx.py”,第181行,在next_feed中        - 打印(批处理(batch_query))
  TypeError:'int'对象不可调用

如果我没记错的话,就会发生这种情况batch_query必须被赋予一个int(类似于batch_query = 1),尽管我的代码中没有这种操作。

有关为何会发生这种情况的任何想法吗?

0 个答案:

没有答案