[英]How does argmax work when given a 3d tensor - tensorflow
I was wondering how does argmax work when given a 3D tensor.我想知道当给定 3D 张量时 argmax 是如何工作的。 I know what happens when it has a 2D tesnor but 3D is confusing me a lot.
我知道当它有一个二维张量时会发生什么,但是 3D 让我很困惑。
Example:例子:
import tensorflow as tf
import numpy as np
sess = tf.Session()
coordinates = np.random.randint(0, 100, size=(3, 3, 2))
coordinates
Out[20]:
array([[[15, 23],
[ 3, 1],
[80, 56]],
[[98, 95],
[97, 82],
[10, 37]],
[[65, 32],
[25, 39],
[54, 68]]])
sess.run([tf.argmax(coordinates, axis=1)])
Out[21]:
[array([[2, 2],
[0, 0],
[0, 2]], dtype=int64)]
tf.argmax
returns the index of the maximum value, as per the axis specified. tf.argmax
根据指定的轴返回最大值的索引。 The specified axis will be crushed, and the index of the maximum value of every unit will be returned.指定轴被压碎,返回每个单位最大值的索引。 The returned shape will have the same shape, except the the specified axis that will disappear.
返回的形状将具有相同的形状,除了将消失的指定轴。 I'll make examples with
tf.reduce_max
so we can follow the values.我将用
tf.reduce_max
做例子,这样我们就可以遵循这些值。
Let's start with your array:让我们从您的数组开始:
x = np.array([[[15, 23],
[3, 1],
[80, 56]],
[[98, 95],
[97, 82],
[10, 37]],
[[65, 32],
[25, 39],
[54, 68]]])
see tf.reduce_max(x, axis=0)
见
tf.reduce_max(x, axis=0)
([[[15, 23],
[3, 1],
[80, 56]],
[[98, 95], ^
^ ^ [97, 82],
^ ^ [10, 37]],
[[65, 32],
[25, 39],
[54, 68]]])
^
<tf.Tensor: shape=(3, 2), dtype=int32, numpy=
array([[98, 95],
[97, 82],
[80, 68]])>
now tf.reduce_max(x, 1)
现在
tf.reduce_max(x, 1)
([[[15, 23], [[98, 95], [[65, 32],
^ ^ ^
[3, 1], [97, 82], [25, 39],
[80, 56]], [10, 37]], [54, 68]]])
^ ^ ^
<tf.Tensor: shape=(3, 2), dtype=int32, numpy=
array([[80, 56],
[98, 95],
[65, 68]])>
now tf.reduce_max(x, axis=2)
现在
tf.reduce_max(x, axis=2)
([[[15, 23],
^
[3, 1],
^
[80, 56]],
^
[[98, 95],
^
[97, 82],
^
[10, 37]],
^
[[65, 32],
^
[25, 39],
^
[54, 68]]])
^
<tf.Tensor: shape=(3, 3), dtype=int32, numpy=
array([[23, 3, 80],
[98, 97, 37],
[65, 39, 68]])>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.