[TensorFlow] demo1 tf.random_uniform 函数

tensorflow/tensorflow/python/ops的 random_ops.py 文件有定义

# pylint: disable=protected-access
def random_normal(shape,
                  mean=0.0,
                  stddev=1.0,
                  dtype=dtypes.float32,
                  seed=None,
                  name=None):
  """Outputs random values from a normal distribution.

  Args:
    shape: A 1-D integer Tensor or Python array. The shape of the output tensor.
    mean: A 0-D Tensor or Python value of type `dtype`. The mean of the normal
      distribution.
    stddev: A 0-D Tensor or Python value of type `dtype`. The standard deviation
      of the normal distribution.
    dtype: The type of the output.
    seed: A Python integer. Used to create a random seed for the distribution.
      See
      @{tf.set_random_seed}
      for behavior.
    name: A name for the operation (optional).

  Returns:
    A tensor of the specified shape filled with random normal values.
  """
  with ops.name_scope(name, "random_normal", [shape, mean, stddev]) as name:
    shape_tensor = _ShapeTensor(shape)
    mean_tensor = ops.convert_to_tensor(mean, dtype=dtype, name="mean")
    stddev_tensor = ops.convert_to_tensor(stddev, dtype=dtype, name="stddev")
    seed1, seed2 = random_seed.get_seed(seed)
    rnd = gen_random_ops._random_standard_normal(
        shape_tensor, dtype, seed=seed1, seed2=seed2)
    mul = rnd * stddev_tensor
    value = math_ops.add(mul, mean_tensor, name=name)
    return value


可以看出,api r1.3(官网)和api r1.4(github)上的说明是有不同的。函数名一样,但是我们需要知道传入的参数的不同。

在api r1.3中

random_uniform(
    shape,
    minval=0,
    maxval=None,

    dtype=tf.float32,
    seed=None,
    name=None
)

参数:
shape:一维整数张量或Python数组。 输出张量的形状。
minval:dtype类型的0-D张量或Python值。 生成的随机值范围的下限。 默认为0。
maxval:类型为dtype的0-D张量或Python值。 要生成的随机值范围的上限。 如果dtype是浮点,则默认为1。
dtype:输出的类型:“float16,float32,float64,int32或orint64”。
seed:一个Python整数。 用于为分发创建一个随机种子。 有关行为,请参阅tf.set_random_seed。
name:操作的名称(可选)。

============================================

在api1.4中

参数:

def random_normal(shape,

                  mean=0.0,
                  stddev=1.0,

                  dtype=dtypes.float32,
                  seed=None,
                  name=None):

shape: A 1-D integer Tensor or Python array. The shape of the output tensor.
    mean: A 0-D Tensor or Python value of type `dtype`. The mean of the normal
      distribution.
    stddev: A 0-D Tensor or Python value of type `dtype`. The standard deviation
      of the normal distribution.
    dtype: The type of the output.
    seed: A Python integer. Used to create a random seed for the distribution.
      See
      @{tf.set_random_seed}
      for behavior.
    name: A name for the operation (optional).

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值