Row with Highest Mean

0
easy

Compute the mean for each row of a 2D tensor and return the index of the row with the highest mean value. For example, if your tensor is `[[1, 2, 3], [4, 5, 6], [7, 8, 9]]`, the means for each row are `[2, 5, 8]`. Thus, the expected output should be `2`, as the third row (0-indexed) has the highest mean.

To solve this exercise, first compute the mean of each row using `torch.mean(tensor, dim=1)`. This will give you a 1D tensor with the means of each row. Then, use `torch.argmax()` to get the index of the highest mean value.

Examples:

1.0
2
3
4
5
6
7
8
9
2
10.0
20
30
40
50
60
2

Loading...
2024 © TensorGym
Contrinbute | Contact | Copyright | 𝕏