0


深入浅出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
  """
  returnrank_internal(input, name, optimize=True)

本文转载自: https://blog.csdn.net/hy592070616/article/details/129267285
版权归原作者 von Neumann 所有, 如有侵权,请联系我们删除。

“深入浅出TensorFlow2函数——tf.rank”的评论:

还没有评论