- paddle.fluid.lod_tensor. create_random_int_lodtensor ( recursive_seq_lens, base_shape, place, low, high )
Create a LoDTensor containing random integers.
The implementation is as follows:
Obtain the shape of output LoDTensor based on
base_shape. The first dimension of the shape is the total length of sequences, while the other dimensions are the same as
Create a numpy array of random integers, and parse the created numpy array as parameter
dataof api_fluid_create_lod_tensor to create the output LoDTensor.
Suppose we want to create a LoDTensor to hold data for 2 sequences, where the dimension of the sequences are [2, 30] and [3, 30] respectively. The
recursive_seq_lenswould be [[2, 3]], and
base_shapewould be  (the other dimensions excluding the sequence length). Therefore, the shape of the output LoDTensor would be [5, 30], where the first dimension 5 is the total lengths of the sequences, and the other dimensions are
recursive_seq_lens (list[list[int]]) – a list of lists indicating the length-based LoD info.
base_shape (list[int]) – the shape of the output LoDTensor excluding the first dimension.
place (CPUPlace|CUDAPlace) – CPU or GPU place indicating where the data in the created LoDTensor will be stored.
low (int) – the lower bound of the random integers.
high (int) – the upper bound of the random integers.
A LoDTensor with tensor data and recursive_seq_lens info, whose data is inside [low, high].
import paddle.fluid as fluid t = fluid.create_random_int_lodtensor(recursive_seq_lens=[[2, 3]], base_shape=, place=fluid.CPUPlace(), low=0, high=10) print(t.shape()) # [5, 30]