[PyTorch] I was a little lost in torch.max ()

Introduction

I didn't understand it in the PyTorch documentation, so I'll leave it. Code from Documentation

How to use torch.max ()

1. For 1D tensor

a = torch.randn(1, 3)
a
tensor([[ 0.6763,  0.7445, -2.2369]])
torch.max(a)
tensor(0.7445)

Yeah, it returns the element with the maximum value of the simplest one-dimensional array

For 2D tensors

a = torch.randn(4, 4)
a
tensor([[-1.2360, -0.2942, -0.1222,  0.8475],
        [ 1.1949, -1.1127, -2.2379, -0.6702],
        [ 1.5717, -0.9207,  0.1297, -1.8768],
        [-0.6172,  1.0036, -0.6060, -0.2432]])
torch.max(a, 1)
torch.return_types.max(values=tensor([0.8475, 1.1949, 1.5717, 1.0036]), indices=tensor([3, 0, 0, 1]))

I didn't really understand the second argument of this It was the axis of numpy. So personally

a = torch.randn(4, 4)
a
tensor([[-1.2360, -0.2942, -0.1222,  0.8475],
        [ 1.1949, -1.1127, -2.2379, -0.6702],
        [ 1.5717, -0.9207,  0.1297, -1.8768],
        [-0.6172,  1.0036, -0.6060, -0.2432]])
axis = 1
torch.max(a, axis)
torch.return_types.max(values=tensor([0.8475, 1.1949, 1.5717, 1.0036]), indices=tensor([3, 0, 0, 1]))

It is easier to understand.

torch.max(a, axis)Such usage is used in classification.


 By the way, although it is for myself, axis is the axis! (```axis = 0: col, axis = 1: row```)

# in conclusion
 I'm still swayed by libraries and math, so I want to be able to use it well as soon as possible.


Recommended Posts

[PyTorch] I was a little lost in torch.max ()
Draw a graph in Julia ... I tried a little analysis
A word that I was interested in as a programming beginner
I get a UnicodeDecodeError in mecab-python3
I got lost in the maze
I get a KeyError in pyclustering.xmeans
I want to print in a comprehension
I made a payroll program in Python!
I started Node.js in a virtual environment
I created a password tool in Python.
What I was addicted to when creating a web application in a windows environment
I was in vain because I couldn't get a send parent order with pybitflyer
When I get a chromedriver error in Selenium
A memo that I wrote a quicksort in Python
I was able to recurse in Python: lambda
I want to create a window in Python
I tried playing a typing game in Python
I thought a little about TensorFlow's growing API
I wrote a class in Python3 and Java
[Memo] I tried a pivot table in Python
I wrote a design pattern in kotlin Prototype
I tried adding a Python3 module in C
I wrote a Japanese parser in Japanese using pyparsing.
I made a Caesar cryptographic program in Python.
I did a little research on the class
I was soberly addicted to calling awscli from a Python 2.7 script registered in crontab
I want to embed a variable in a Python string
I want to easily implement a timeout in python
I made a prime number generation program in Python
I wrote a design pattern in kotlin Factory edition
I want to transition with a button in flask
I get a java.util.regex.PatternSyntaxException when splitting a string in PySpark
I was in trouble because I couldn't push with heroku
I wrote a design pattern in kotlin Builder edition
[PyTorch] A little understanding of CrossEntropyLoss with mathematical formulas
I wrote a design pattern in kotlin Adapter edition
I tried to implement a pseudo pachislot in Python
I wrote a design pattern in kotlin, Iterator edition
I want to work with a robot in python.
A story that I was addicted to at np.where
I participated in competitive programming in a week after I started programming
I made a prime number generation program in Python 2
I can't manipulate iframes in a page with Selenium
I was able to repeat it in Python: lambda
I wrote a design pattern in kotlin Template edition
I was addicted to trying logging.getLogger in Flask 1.1.x
PyTorch Learning Note 2 (I tried using a pre-trained model)
I implemented a Vim-like replacement command in Slackbot #Python
I used bugspots, a bug prediction tool in mercurial
What I was addicted to when dealing with huge files in a Linux 32bit environment
The story I was addicted to when I specified nil as a function argument in Go