如何同时迭代两个变量?

时间:2017-09-30 20:14:28

标签: python list for-loop

我的代码如下:

# the iterator to get the next_element for one sample (in sequence)
iterator, next_element = read_batch_DatasetAPI(
    in_tf_FWN,  # the file name of the tfrecords containing ~200,000 Sequence Examples
    batch_size = 1,  # works when it is 1, doesn't work if > 1
    num_epochs = 1,
    buffer_size = None)

# tf session initialization
sess = tf.Session()
sess.run(tf.global_variables_initializer())

## reset the iterator to the beginning
sess.run(iterator.initializer)

try:
    step = 0

    while (True):

        # get the next batch data
        length, site_code_raw, Date_Local_raw, Time_Local_raw, \
        Orig_RefPts, tgt_location, tgt_vale = sess.run(next_element)

        step = step + 1

except tf.errors.OutOfRangeError:
    # Task Done (all SeqExs have been visited)
    print("closing ", in_tf_FWN)

except ValueError as err:
    print("Error: {}".format(err.args))

except Exception as err:
    print("Error: {}".format(err.args))

我希望你能帮助我。

1 个答案:

答案 0 :(得分:0)

您可以使用zip(*iterables)

for startDate, endDate in zip(startDates, endDates):
    print startDate
    print endDate

输出:

2011-01-01
2013-01-01
2012-01-01
2014-01-01