当前位置: 首页>>代码示例>>Python>>正文


Python gen_array_ops.rank方法代码示例

本文整理汇总了Python中tensorflow.python.ops.gen_array_ops.rank方法的典型用法代码示例。如果您正苦于以下问题:Python gen_array_ops.rank方法的具体用法?Python gen_array_ops.rank怎么用?Python gen_array_ops.rank使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tensorflow.python.ops.gen_array_ops的用法示例。


在下文中一共展示了gen_array_ops.rank方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: rank_internal

# 需要导入模块: from tensorflow.python.ops import gen_array_ops [as 别名]
# 或者: from tensorflow.python.ops.gen_array_ops import rank [as 别名]
def rank_internal(input, name=None, optimize=True):
  # pylint: disable=redefined-builtin
  """Returns the rank of a tensor.

  Args:
    input: A `Tensor` or `SparseTensor`.
    name: A name for the operation (optional).
    optimize: if true, encode the rank as a constant when possible.

  Returns:
    A `Tensor` of type `int32`.
  """
  with ops.name_scope(name, "Rank", [input]) as name:
    if isinstance(
        input, (sparse_tensor.SparseTensor, sparse_tensor.SparseTensorValue)):
      return gen_array_ops.size(input.dense_shape, name=name)
    else:
      input_tensor = ops.convert_to_tensor(input)
      input_shape = input_tensor.get_shape()
      if optimize and input_shape.ndims is not None:
        return constant(input_shape.ndims, dtypes.int32, name=name)
      return gen_array_ops.rank(input, name=name) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:24,代码来源:array_ops.py

示例2: rank_internal

# 需要导入模块: from tensorflow.python.ops import gen_array_ops [as 别名]
# 或者: from tensorflow.python.ops.gen_array_ops import rank [as 别名]
def rank_internal(input, name=None, optimize=True):
  # pylint: disable=redefined-builtin
  """Returns the rank of a tensor.

  Args:
    input: A `Tensor` or `SparseTensor`.
    name: A name for the operation (optional).
    optimize: if true, encode the rank as a constant when possible.

  Returns:
    A `Tensor` of type `int32`.
  """
  with ops.name_scope(name, "Rank", [input]) as name:
    if isinstance(
        input, (sparse_tensor.SparseTensor, sparse_tensor.SparseTensorValue)):
      return gen_array_ops.size(input.shape, name=name)
    else:
      input_tensor = ops.convert_to_tensor(input)
      input_shape = input_tensor.get_shape()
      if optimize and input_shape.ndims is not None:
        return constant(input_shape.ndims, dtypes.int32, name=name)
      return gen_array_ops.rank(input, name=name) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:24,代码来源:array_ops.py

示例3: rank_internal

# 需要导入模块: from tensorflow.python.ops import gen_array_ops [as 别名]
# 或者: from tensorflow.python.ops.gen_array_ops import rank [as 别名]
def rank_internal(input, name=None, optimize=True):
  # pylint: disable=redefined-builtin
  """Returns the rank of a tensor.

  Args:
    input: A `Tensor` or `SparseTensor`.
    name: A name for the operation (optional).
    optimize: if true, encode the rank as a constant when possible.

  Returns:
    A `Tensor` of type `int32`.
  """
  with ops.name_scope(name, "Rank", [input]) as name:
    if isinstance(input, (sparse_tensor.SparseTensor,
                          sparse_tensor.SparseTensorValue)):
      return gen_array_ops.size(input.dense_shape, name=name)
    else:
      input_tensor = ops.convert_to_tensor(input)
      input_shape = input_tensor.get_shape()
      if optimize and input_shape.ndims is not None:
        return constant(input_shape.ndims, dtypes.int32, name=name)
      return gen_array_ops.rank(input, name=name) 
开发者ID:PacktPublishing,项目名称:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代码行数:24,代码来源:array_ops.py

示例4: broadcast_dynamic_shape

# 需要导入模块: from tensorflow.python.ops import gen_array_ops [as 别名]
# 或者: from tensorflow.python.ops.gen_array_ops import rank [as 别名]
def broadcast_dynamic_shape(shape_x, shape_y):
  # pylint: disable=protected-access
  """Returns the broadcasted dynamic shape between `shape_x` and `shape_y`.

  Args:
    shape_x: A rank 1 integer `Tensor`, representing the shape of x.
    shape_y: A rank 1 integer `Tensor`, representing the shape of y.
  Returns:
    A rank 1 integer `Tensor` representing the broadcasted shape.
  """
  return gen_array_ops._broadcast_args(shape_x, shape_y)
  # pylint: enable=protected-access 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:14,代码来源:array_ops.py

示例5: rank

# 需要导入模块: from tensorflow.python.ops import gen_array_ops [as 别名]
# 或者: from tensorflow.python.ops.gen_array_ops import rank [as 别名]
def rank(input, name=None):
  # pylint: disable=redefined-builtin
  """Returns the rank of a tensor.

  This operation returns an integer representing the rank of `input`.

  For example:

  ```python
  # 't' is [[[1, 1, 1], [2, 2, 2]], [[3, 3, 3], [4, 4, 4]]]
  # shape of tensor 't' is [2, 2, 3]
  rank(t) ==> 3
  ```

  **Note**: The rank of a tensor is not the same as the rank of a matrix. The
  rank of a tensor is the number of indices required to uniquely select each
  element of the tensor. Rank is also known as "order", "degree", or "ndims."

  Args:
    input: A `Tensor` or `SparseTensor`.
    name: A name for the operation (optional).

  Returns:
    A `Tensor` of type `int32`.

  @compatibility(numpy)
  Equivalent to np.ndim
  @end_compatibility
  """
  return rank_internal(input, name, optimize=True) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:32,代码来源:array_ops.py

示例6: broadcast_dynamic_shape

# 需要导入模块: from tensorflow.python.ops import gen_array_ops [as 别名]
# 或者: from tensorflow.python.ops.gen_array_ops import rank [as 别名]
def broadcast_dynamic_shape(shape_x, shape_y):
  # pylint: disable=protected-access
  """Returns the broadcasted dynamic shape between `shape_x` and `shape_y`.

  Args:
    shape_x: A rank 1 integer `Tensor`, representing the shape of x.
    shape_y: A rank 1 integer `Tensor`, representing the shape of x.
  Returns:
    A rank 1 integer `Tensor` representing the broadcasted shape.
  """
  return gen_array_ops._broadcast_args(shape_x, shape_y)
  # pylint: enable=protected-access 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:14,代码来源:array_ops.py

示例7: rank

# 需要导入模块: from tensorflow.python.ops import gen_array_ops [as 别名]
# 或者: from tensorflow.python.ops.gen_array_ops import rank [as 别名]
def rank(input, name=None):
  # pylint: disable=redefined-builtin
  """Returns the rank of a tensor.

  This operation returns an integer representing the rank of `input`.

  For example:

  ```python
  # 't' is [[[1, 1, 1], [2, 2, 2]], [[3, 3, 3], [4, 4, 4]]]
  # shape of tensor 't' is [2, 2, 3]
  rank(t) ==> 3
  ```

  **Note**: The rank of a tensor is not the same as the rank of a matrix. The
  rank of a tensor is the number of indices required to uniquely select each
  element of the tensor. Rank is also known as "order", "degree", or "ndims."

  Args:
    input: A `Tensor` or `SparseTensor`.
    name: A name for the operation (optional).

  Returns:
    A `Tensor` of type `int32`.
  """
  return rank_internal(input, name, optimize=True) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:28,代码来源:array_ops.py

示例8: pack

# 需要导入模块: from tensorflow.python.ops import gen_array_ops [as 别名]
# 或者: from tensorflow.python.ops.gen_array_ops import rank [as 别名]
def pack(values, axis=0, name="pack"):
  """Packs a list of rank-`R` tensors into one rank-`(R+1)` tensor.

  Packs the list of tensors in `values` into a tensor with rank one higher than
  each tensor in `values`, by packing them along the `axis` dimension.
  Given a list of length `N` of tensors of shape `(A, B, C)`;

  if `axis == 0` then the `output` tensor will have the shape `(N, A, B, C)`.
  if `axis == 1` then the `output` tensor will have the shape `(A, N, B, C)`.
  Etc.

  For example:

  ```prettyprint
  # 'x' is [1, 4]
  # 'y' is [2, 5]
  # 'z' is [3, 6]
  pack([x, y, z]) => [[1, 4], [2, 5], [3, 6]]  # Pack along first dim.
  pack([x, y, z], axis=1) => [[1, 2, 3], [4, 5, 6]]
  ```

  This is the opposite of unpack.  The numpy equivalent is

      tf.pack([x, y, z]) = np.asarray([x, y, z])

  Args:
    values: A list of `Tensor` objects with the same shape and type.
    axis: An `int`. The axis to pack along. Defaults to the first dimension.
      Supports negative indexes.
    name: A name for this operation (optional).

  Returns:
    output: A packed `Tensor` with the same type as `values`.

  Raises:
    ValueError: If `axis` is out of the range [-(R+1), R+1).
  """
  return stack(values, axis, name)


# pylint: disable=invalid-name 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:43,代码来源:array_ops.py

示例9: _TileShape

# 需要导入模块: from tensorflow.python.ops import gen_array_ops [as 别名]
# 或者: from tensorflow.python.ops.gen_array_ops import rank [as 别名]
def _TileShape(op):
  """Shape function for the Tile op.

  This op has two inputs:

  * input: A rank-N tensor.
  * multiples: A length-N vector, in which the i^th element contains
    the factor by which `input` will be tiled in the i^th dimension.

  It has one output, which has the same rank as input, and additional
  elements according to the values in multiples

  Args:
    op: A Tile Operation.

  Returns:
    A single-element list containing the shape of the output.
  """
  multiples_shape = op.inputs[1].get_shape().with_rank(1)
  input_shape = op.inputs[0].get_shape().with_rank(multiples_shape[0].value)
  # NOTE(mrry): Represent `multiples` as a `TensorShape` because (i)
  # it is a vector of non-negative integers, and (ii) doing so allows
  # us to handle partially-known multiples.
  multiples = tensor_util.constant_value_as_shape(op.inputs[1]).with_rank(
      input_shape.ndims)
  if multiples.ndims is None:
    return [tensor_shape.unknown_shape()]
  else:
    output_dims = []
    for dim, multiple in zip(input_shape.dims, multiples.dims):
      output_dims.append(dim * multiple)
    return [tensor_shape.TensorShape(output_dims)] 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:34,代码来源:array_ops.py

示例10: broadcast_dynamic_shape

# 需要导入模块: from tensorflow.python.ops import gen_array_ops [as 别名]
# 或者: from tensorflow.python.ops.gen_array_ops import rank [as 别名]
def broadcast_dynamic_shape(shape_x, shape_y):
  # pylint: disable=protected-access
  """Returns the broadcasted dynamic shape between `shape_x` and `shape_y`.

  Args:
    shape_x: A rank 1 integer `Tensor`, representing the shape of x.
    shape_y: A rank 1 integer `Tensor`, representing the shape of y.

  Returns:
    A rank 1 integer `Tensor` representing the broadcasted shape.
  """
  return gen_array_ops._broadcast_args(shape_x, shape_y)
  # pylint: enable=protected-access 
开发者ID:PacktPublishing,项目名称:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代码行数:15,代码来源:array_ops.py

示例11: rank

# 需要导入模块: from tensorflow.python.ops import gen_array_ops [as 别名]
# 或者: from tensorflow.python.ops.gen_array_ops import rank [as 别名]
def rank(input, name=None):
  # pylint: disable=redefined-builtin
  """Returns the rank of a tensor.

  Returns a 0-D `int32` `Tensor` representing the rank of `input`.

  For example:

  ```python
  # shape of tensor 't' is [2, 2, 3]
  t = tf.constant([[[1, 1, 1], [2, 2, 2]], [[3, 3, 3], [4, 4, 4]]])
  tf.rank(t)  # 3
  ```

  **Note**: The rank of a tensor is not the same as the rank of a matrix. The
  rank of a tensor is the number of indices required to uniquely select each
  element of the tensor. Rank is also known as "order", "degree", or "ndims."

  Args:
    input: A `Tensor` or `SparseTensor`.
    name: A name for the operation (optional).

  Returns:
    A `Tensor` of type `int32`.

  @compatibility(numpy)
  Equivalent to np.ndim
  @end_compatibility
  """
  return rank_internal(input, name, optimize=True) 
开发者ID:PacktPublishing,项目名称:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代码行数:32,代码来源:array_ops.py

示例12: _normalize_sparse_shape

# 需要导入模块: from tensorflow.python.ops import gen_array_ops [as 别名]
# 或者: from tensorflow.python.ops.gen_array_ops import rank [as 别名]
def _normalize_sparse_shape(shape, name):
  """Returns a tuple of (Tensor or None, rank or None)."""
  if shape is None:
    return (None, None)
  rank = shape.get_shape()[0] if isinstance(shape, ops.Tensor) else len(shape)
  if not isinstance(shape, ops.Tensor) and None in shape:
    return (None, rank)
  return (ops.convert_to_tensor(shape, dtype=dtypes.int64, name=name), rank) 
开发者ID:PacktPublishing,项目名称:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代码行数:10,代码来源:array_ops.py

示例13: _all_dimensions

# 需要导入模块: from tensorflow.python.ops import gen_array_ops [as 别名]
# 或者: from tensorflow.python.ops.gen_array_ops import rank [as 别名]
def _all_dimensions(x):
  """Returns a 1D-tensor listing all dimensions in x."""
  # Fast path: avoid creating Rank and Range ops if ndims is known.
  if isinstance(x, ops.Tensor) and x.get_shape().ndims is not None:
    return constant_op.constant(
        np.arange(x.get_shape().ndims), dtype=dtypes.int32)
  if (isinstance(x, sparse_tensor.SparseTensor) and
      x.dense_shape.get_shape().is_fully_defined()):
    r = x.dense_shape.get_shape()[0].value  # sparse.dense_shape is 1-D.
    return constant_op.constant(np.arange(r), dtype=dtypes.int32)

  # Otherwise, we rely on Range and Rank to do the right thing at run-time.
  return range(0, rank(x)) 
开发者ID:PacktPublishing,项目名称:Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda,代码行数:15,代码来源:array_ops.py

示例14: parallel_stack

# 需要导入模块: from tensorflow.python.ops import gen_array_ops [as 别名]
# 或者: from tensorflow.python.ops.gen_array_ops import rank [as 别名]
def parallel_stack(values, name="parallel_stack"):
  """Stacks a list of rank-`R` tensors into one rank-`(R+1)` tensor in parallel.

  Requires that the shape of inputs be known at graph construction time.

  Packs the list of tensors in `values` into a tensor with rank one higher than
  each tensor in `values`, by packing them along the first dimension.
  Given a list of length `N` of tensors of shape `(A, B, C)`; the `output`
  tensor will have the shape `(N, A, B, C)`.

  For example:

  ```prettyprint
  # 'x' is [1, 4]
  # 'y' is [2, 5]
  # 'z' is [3, 6]
  parallel_stack([x, y, z]) => [[1, 4], [2, 5], [3, 6]]
  ```

  The difference between stack and parallel_stack is that stack requires all
  of the inputs be computed before the operation will begin but doesn't require
  that the input shapes be known during graph construction.  Parallel stack
  will copy pieces of the input into the output as they become available, in
  some situations this can provide a performance benefit.

  This is the opposite of unstack.  The numpy equivalent is

      tf.parallel_stack([x, y, z]) = np.asarray([x, y, z])

  Args:
    values: A list of `Tensor` objects with the same shape and type.
    name: A name for this operation (optional).

  Returns:
    output: A stacked `Tensor` with the same type as `values`.
  """
  with ops.name_scope(name):
    value_t = ops.convert_to_tensor(values[0])
    value_shape = ops.convert_to_tensor(value_t).get_shape()

    output_shape = tensor_shape.TensorShape([len(values)])
    output_shape = output_shape.concatenate(value_shape)
    # expand_dims converts concat to stack.
    return gen_array_ops._parallel_concat(
        [expand_dims(value, 0) for value in values], shape=output_shape) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:47,代码来源:array_ops.py

示例15: stack

# 需要导入模块: from tensorflow.python.ops import gen_array_ops [as 别名]
# 或者: from tensorflow.python.ops.gen_array_ops import rank [as 别名]
def stack(values, axis=0, name="stack"):
  """Stacks a list of rank-`R` tensors into one rank-`(R+1)` tensor.

  Packs the list of tensors in `values` into a tensor with rank one higher than
  each tensor in `values`, by packing them along the `axis` dimension.
  Given a list of length `N` of tensors of shape `(A, B, C)`;

  if `axis == 0` then the `output` tensor will have the shape `(N, A, B, C)`.
  if `axis == 1` then the `output` tensor will have the shape `(A, N, B, C)`.
  Etc.

  For example:

  ```prettyprint
  # 'x' is [1, 4]
  # 'y' is [2, 5]
  # 'z' is [3, 6]
  stack([x, y, z]) => [[1, 4], [2, 5], [3, 6]]  # Pack along first dim.
  stack([x, y, z], axis=1) => [[1, 2, 3], [4, 5, 6]]
  ```

  This is the opposite of unstack.  The numpy equivalent is

  ```python
  tf.stack([x, y, z]) = np.asarray([x, y, z])
  ```

  Args:
    values: A list of `Tensor` objects with the same shape and type.
    axis: An `int`. The axis to stack along. Defaults to the first dimension.
      Supports negative indexes.
    name: A name for this operation (optional).

  Returns:
    output: A stacked `Tensor` with the same type as `values`.

  Raises:
    ValueError: If `axis` is out of the range [-(R+1), R+1).
  """
  if axis == 0:
    try:
      # If the input is a constant list, it can be converted to a constant op
      return ops.convert_to_tensor(values, name=name)
    except (TypeError, ValueError):
      pass  # Input list contains non-constant tensors

  value_shape = ops.convert_to_tensor(values[0], name=name).get_shape()
  if value_shape.ndims is not None:
    expanded_num_dims = value_shape.ndims + 1
    if axis < -expanded_num_dims or axis >= expanded_num_dims:
      raise ValueError("axis = %d not in [%d, %d)" %
                       (axis, -expanded_num_dims, expanded_num_dims))

  return gen_array_ops._pack(values, axis=axis, name=name)


# pylint: disable=invalid-name 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:59,代码来源:array_ops.py


注:本文中的tensorflow.python.ops.gen_array_ops.rank方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。