Noumpy or tf.Is there a way to get the order of maximum values in a particular dimension in the array?
Simply put, we're going to take the position of the maximum value of a particular row in a place like Pandas.
It's like using Softmax at the end of the Keras model.
I actually used Softmax.
[
[ 0, 0, 0, 2, 9, 4, 5, 5, 5, 5 ],
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
]
In this case, we return [4, 9].
For your information, the actual value is Softmax, so it's a mistake.
python numpy tensorflow
There is argmax in numpy.
import numpy as np
def main():
a = np.array([[0, 0, 0, 2, 9, 4, 5, 5, 5, 5],
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]])
amax = np.argmax(a, axis=1)
print(amax)
if __name__ == "__main__":
main()
>>> a = [[ 0, 0, 0, 2, 9, 4, 5, 5, 5, 5 ], [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]
>>> list(map(lambda x: x.index(max(x)), a))
[4, 9]
© 2024 OneMinuteCode. All rights reserved.