create_random_int_lodtensor¶
- paddle.fluid.lod_tensor. create_random_int_lodtensor ( recursive_seq_lens, base_shape, place, low, high ) [source]
-
- api_attr
-
Static Graph
Create a LoDTensor containing random integers.
The implementation is as follows:
Obtain the shape of output LoDTensor based on
recursive_seq_lens
andbase_shape
. The first dimension of the shape is the total length of sequences, while the other dimensions are the same asbase_shape
.Create a numpy array of random integers, and parse the created numpy array as parameter
data
of 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_lens
would be [[2, 3]], andbase_shape
would be [30] (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 arebase_shape
.- Parameters
-
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.
- Returns
-
A LoDTensor with tensor data and recursive_seq_lens info, whose data is inside [low, high].
Examples
import paddle.fluid as fluid t = fluid.create_random_int_lodtensor(recursive_seq_lens=[[2, 3]], base_shape=[30], place=fluid.CPUPlace(), low=0, high=10) print(t.shape()) # [5, 30]