标签:key 向量 pre nump fence operator ble vector 返回
vector为向量,返回行或列的最大值的索引号;
vector为矩阵,返回值是向量,返回每行或每列的最大值的索引号。
vector为向量或者矩阵
axis = 0 或1
0:返回vector中每列的最大值的索引号
1:返回vector中每行的最大索引号
import numpy as np
import tensorflow as tf
a=np.array([[1,2,3]])
with tf.Session() as sess:
print(sess.run(tf.argmax(a,1)))
>>>[2]
#表示返回行向量[1,2,3]的行最大值3的索引号是2
import numpy as np
import tensorflow as tf
a=np.array([[1,2,3]])
with tf.Session() as sess:
print(sess.run(tf.argmax(a,0)))
>>>[0 0 0]
#表示返回行向量[1,2,3]的每列最大值,因为每列只有一个数,所以返回下标为0 0 0
import numpy as np
import tensorflow as tf
a=np.array([[1,2,3],[4,5,2],[-1,2,3]])
with tf.Session() as sess:
print(sess.run(tf.argmax(a,0)))
>>>[1 1 0]
#表示返回矩阵[1,2,3;4,5,2;-1,2,3]中每列的最大值的索引号1 1 0
import numpy as np
import tensorflow as tf
a=np.array([[1],[2],[5]])
with tf.Session() as sess:
print(sess.run(tf.argmax(a,0)))
>>>[2]
#表示返回列向量的列最大值的索引号
import numpy as np
import tensorflow as tf
a=np.array([[1],[2],[5]])
with tf.Session() as sess:
print(sess.run(tf.argmax(a,1)))
>>>[0,0,0]
#表示返回列向量的行最大值的索引号,因为每行只有一个数,所以返回0 0 0
标签:key 向量 pre nump fence operator ble vector 返回
原文地址:https://www.cnblogs.com/Leonida/p/14224789.html