ones¶
- paddle.fluid.layers.tensor. ones ( shape, dtype, force_cpu=False ) [source]
- 
         The OP creates a tensor of specified shapeanddtype, and fills it with 1. Itsstop_gradientwill be set to True to stop gradient computation.- Parameters
- 
           - shape (tuple|list|Tensor) – Shape of output Tensor, the data type of shape is int32 or int64. 
- dtype (np.dtype|str) – Data type of output Tensor, it supports bool, float16, float32, float64, int32 and int64. 
- force_cpu (bool, optional) – Whether force to store the output Tensor in CPU memory. If - force_cpuis False, the output Tensor will be stored in running device memory. Default: False.
 
- Returns
- 
           A tensor of data type dtypewith shapeshapeand all elements set to 1.
- Return type
- 
           Tensor 
 Examples import paddle.fluid as fluid data0 = fluid.layers.ones(shape=[2, 4], dtype='float32') # [[1., 1., 1., 1.], [1., 1., 1., 1.]] # shape is a Tensor shape = fluid.layers.fill_constant(shape=[2], dtype='int32', value=2) data1 = fluid.layers.ones(shape=shape, dtype='int32') #[[1, 1], [1, 1]] 
