Esempio n. 1
0
def poisson(lam=1.0, size=None):
    if size is None:
        size = ()
    elif np_utils.isscalar(size):
        size = (size, )
    return np_utils.tensor_to_ndarray(
        random_ops.random_poisson(shape=size, lam=lam, dtype=np_dtypes.int64))
Esempio n. 2
0
def standard_normal(size=None):
  # TODO(wangpeng): Use new stateful RNG
  if size is None:
    size = ()
  elif np_utils.isscalar(size):
    size = (size,)
  dtype = np_dtypes.default_float_type()
  return random_ops.random_normal(size, dtype=dtype)
Esempio n. 3
0
def randn(*args):
    """Returns samples from a normal distribution.

  Uses `tf.random_normal`.

  Args:
    *args: The shape of the output array.

  Returns:
    An ndarray with shape `args` and dtype `float64`.
  """
    # TODO(wangpeng): Use new stateful RNG
    if np_utils.isscalar(args):
        args = (args, )
    dtype = np_dtypes.default_float_type()
    return random_ops.random_normal(args, dtype=dtype)
Esempio n. 4
0
def randn(*args):
    """Returns samples from a normal distribution.

  Uses `tf.random_normal`.

  Args:
    *args: The shape of the output array.

  Returns:
    An ndarray with shape `args` and dtype `float64`.
  """
    # TODO(wangpeng): Use new stateful RNG
    if np_utils.isscalar(args):
        args = (args, )
    return np_utils.tensor_to_ndarray(
        random_ops.random_normal(args, dtype=DEFAULT_RANDN_DTYPE))
Esempio n. 5
0
def full(shape, fill_value, dtype=None):  # pylint: disable=redefined-outer-name
    """Returns an array with given shape and dtype filled with `fill_value`.

  Args:
    shape: A valid shape object. Could be a native python object or an object of
      type ndarray, numpy.ndarray or tf.TensorShape.
    fill_value: array_like. Could be an ndarray, a Tensor or any object that can
      be converted to a Tensor using `tf.convert_to_tensor`.
    dtype: Optional, defaults to dtype of the `fill_value`. The type of the
      resulting ndarray. Could be a python type, a NumPy type or a TensorFlow
      `DType`.

  Returns:
    An ndarray.

  Raises:
    ValueError: if `fill_value` can not be broadcast to shape `shape`.
  """
    fill_value = asarray(fill_value, dtype=dtype)
    if np_utils.isscalar(shape):
        shape = array_ops.reshape(shape, [1])
    return np_arrays.tensor_to_ndarray(
        array_ops.broadcast_to(fill_value.data, shape))
Esempio n. 6
0
def poisson(lam=1.0, size=None):
  if size is None:
    size = ()
  elif np_utils.isscalar(size):
    size = (size,)
  return random_ops.random_poisson(shape=size, lam=lam, dtype=np_dtypes.int_)