深入浅出TensorFlow2函数——tf.rank

分类目录:《深入浅出TensorFlow2函数》总目录

语法

tf.rank(input, name=None)

参数

  • inputtf.Tensortf.SparseTensor
  • name:[可选] 操作的名称

返回值

张量input的维度,是一个int32类型的张量

实例

输入:

t = tf.constant([[[1, 1, 1], [2, 2, 2]], [[3, 3, 3], [4, 4, 4]]])
tf.rank(t)

输出:

<tf.Tensor: shape=(), dtype=int32, numpy=3>

函数实现

@tf_export("rank")
@dispatch.add_dispatch_support
def rank(input, name=None):
  # pylint: disable=redefined-builtin
  """Returns the rank of a tensor.
  See also `tf.shape`.
  Returns a 0-D `int32` `Tensor` representing the rank of `input`.
  For example:

  **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)

文章出处登录后可见!

已经登录?立即刷新

共计人评分,平均

到目前为止还没有投票!成为第一位评论此文章。

(0)
青葱年少的头像青葱年少普通用户
上一篇 2023年7月6日
下一篇 2023年7月6日

相关推荐