分类目录:《深入浅出TensorFlow2函数》总目录
语法
tf.rank(input, name=None)
参数
-
input
:tf.Tensor
或tf.SparseTensor
-
name
:[可选] 操作的名称
返回值
张量input
的维度,是一个int32
类型的张量
实例
输入:文章来源:https://www.toymoban.com/news/detail-529857.html
t = tf.constant([[[1, 1, 1], [2, 2, 2]], [[3, 3, 3], [4, 4, 4]]])
tf.rank(t)
输出:文章来源地址https://www.toymoban.com/news/detail-529857.html
<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)
到了这里,关于深入浅出TensorFlow2函数——tf.rank的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!