分类目录:《深入浅出TensorFlow2函数》总目录
绘制shape
个来自每个给定泊松分布的样本。文章来源:https://www.toymoban.com/news/detail-511030.html
语法
tf.random.poisson(
shape,
lam,
dtype=tf.dtypes.float32,
seed=None,
name=None
)
参数
-
shape
:输出张量的形状,为一个一维整数张量或Python数组。 -
lam
:样本提供描述泊松分布的参数。 -
dtype
:输出的浮点类型:float16
、bfloat16
、float32
、float64
,默认为float32
。 -
seed
:[int
] 用于为创建分布的随机种子。可参考tf.random.set_seed
。 -
name
:[可选] 操作的名称。
返回值
用泊松分布值填充的指定形状的张量。文章来源地址https://www.toymoban.com/news/detail-511030.html
实例
samples = tf.random.poisson([10], [0.5, 1.5])
# samples has shape [10, 2], where each slice [:, 0] and [:, 1] represents
# the samples drawn from each distribution
samples = tf.random.poisson([7, 5], [12.2, 3.3])
# samples has shape [7, 5, 2], where each slice [:, :, 0] and [:, :, 1]
# represents the 7x5 samples drawn from each of the two distributions
函数实现
@tf_export("random.poisson", v1=[])
@dispatch.add_dispatch_support
def random_poisson_v2(shape, lam, dtype=dtypes.float32, seed=None, name=None):
"""Draws `shape` samples from each of the given Poisson distribution(s).
`lam` is the rate parameter describing the distribution(s).
Example:
Args:
shape: A 1-D integer Tensor or Python array. The shape of the output samples
to be drawn per "rate"-parameterized distribution.
lam: A Tensor or Python value or N-D array of type `dtype`.
`lam` provides the rate parameter(s) describing the poisson
distribution(s) to sample.
dtype: The type of the output: `float16`, `float32`, `float64`, `int32` or
`int64`.
seed: A Python integer. Used to create a random seed for the distributions.
See
`tf.random.set_seed`
for behavior.
name: Optional name for the operation.
Returns:
samples: a `Tensor` of shape `tf.concat([shape, tf.shape(lam)], axis=0)`
with values of type `dtype`.
"""
with ops.name_scope(name, "random_poisson", [lam, shape]):
shape = ops.convert_to_tensor(shape, name="shape", dtype=dtypes.int32)
seed1, seed2 = random_seed.get_seed(seed)
result = gen_random_ops.random_poisson_v2(
shape, lam, dtype=dtype, seed=seed1, seed2=seed2)
_maybe_set_static_shape_helper(result, shape, lam)
return result
到了这里,关于深入浅出TensorFlow2函数——tf.random.poisson的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!