chain

paddle.fluid.io.chain(*readers)[source]

Use the input data readers to create a chained data reader. The new created reader chains the outputs of input readers together as its output.

Note:

paddle.reader.chain is the alias of paddle.fluid.io.chain, and paddle.fluid.io.chain is recommended to use.

For example, if three input readers’ outputs are as follows: [0, 0, 0], [10, 10, 10], [20, 20, 20]. The chained reader will output: [[0, 0, 0], [10, 10, 10], [20, 20, 20]].

Parameters

readers (list) – input data readers.

Returns

the new chained data reader.

Return type

callable

Examples

import paddle

def reader_creator_3(start):
    def reader():
        for i in range(start, start + 3):
            yield [i, i, i]
    return reader

c = paddle.reader.chain(reader_creator_3(0), reader_creator_3(10), reader_creator_3(20))
for e in c():
    print(e)
# Output:
# [0, 0, 0]
# [1, 1, 1]
# [2, 2, 2]
# [10, 10, 10]
# [11, 11, 11]
# [12, 12, 12]
# [20, 20, 20]
# [21, 21, 21]
# [22, 22, 22]