What is the meaning of max of a variable?

For e.g. we create a net named ‘net’. y = net(x). what is meaning of y.max(1)? (especially a,b = y.max(1), what does it mean?)I saw the range of max is (-2,1). what does that mean.

2 Likes

https://www.tutorialspoint.com/python/list_max.htm

I think you can relate with this.

Let’s check the docs http://pytorch.org/docs/0.3.1/tensors.html#torch.Tensor.max

y.max(1) takes the max over dimension 1 and returns two values. an example would help.

Supposing we have a tensor y of shape (3, 4) containing

 0.6857  0.1098  0.4687  0.7822
 0.4170  0.2476  0.1339  0.5563
 0.9425  0.8433  0.1335  0.3169

y.max(1) returns two tensors…

# 1. the max value in each row of y
 0.7822
 0.5563
 0.9425
# 2. the column index at which the max value is found.
 3
 3
 0
6 Likes

Why does y.max(1), give the max element in each row? (dimensions in Numpy are 0 indexed- so 0 for row, 1 for coloumn) Why is it different in PyTorch?

max(1) will return the maximal value (and index in PyTorch) in this particular dimension.
Both, numpy and PyTorch return the same values (PyTorch additionally with the indices):

x = np.random.randn(10, 10)
print(x.max(1))
print(torch.from_numpy(x).max(1)[0])
1 Like

Thank you for the examples!