分类目录:《深入浅出TensorFlow2函数》总目录
语法
tf.rank(input, name=None)
参数
input
:tf.Tensor
或tf.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)
文章出处登录后可见!
已经登录?立即刷新