Pytorch疑难小实验:Torch.max() Torch.min()在不同维度上的解释

import torch

torch.manual_seed(2)
Tensor_data = torch.rand((3,3,3))
print(Tensor_data)

enc_opt0_min = Tensor_data.min(dim=0)[0].unsqueeze(2) #取最小值张量 索引舍弃
print("min:",enc_opt0_min)
enc_opt0_max = Tensor_data.max(dim=0)[0].unsqueeze(2)
print("max:",enc_opt0_max)
tensor([[[0.6147, 0.3810, 0.6371],
         [0.4745, 0.7136, 0.6190],
         [0.4425, 0.0958, 0.6142]],

        [[0.0573, 0.5657, 0.5332],
         [0.3901, 0.9088, 0.5334],
         [0.7073, 0.7116, 0.2050]],

        [[0.3078, 0.9809, 0.0103],
         [0.4660, 0.4604, 0.8547],
         [0.4525, 0.6317, 0.4760]]])
min: tensor([[[0.0573],[0.3810],[0.0103]],
			[[0.3901],[0.4604],[0.5334]],
			[[0.4425],[0.0958],[0.2050]]])
max: tensor([[[0.6147],[0.9809],[0.6371]],
	        [[0.4745], [0.9088],[0.8547]],
	        [[0.7073],[0.7116],[0.6142]]])
import torch

torch.manual_seed(2)
Tensor_data = torch.rand((3,3,3))
print(Tensor_data)

enc_opt0_min = Tensor_data.min(dim=1)[0].unsqueeze(2) #取最小值张量 索引舍弃
print("min:",enc_opt0_min)
enc_opt0_max = Tensor_data.max(dim=1)[0].unsqueeze(2)
print("max:",enc_opt0_max)
tensor([[[0.6147, 0.3810, 0.6371],
         [0.4745, 0.7136, 0.6190],
         [0.4425, 0.0958, 0.6142]],

        [[0.0573, 0.5657, 0.5332],
         [0.3901, 0.9088, 0.5334],
         [0.7073, 0.7116, 0.2050]],

        [[0.3078, 0.9809, 0.0103],
         [0.4660, 0.4604, 0.8547],
         [0.4525, 0.6317, 0.4760]]])
min: tensor([[[0.4425],[0.0958],[0.6142]],
			[[0.0573],[0.5657],[0.2050]],
			[[0.3078], [0.4604],[0.0103]]])
max: tensor([[[0.6147],[0.7136],[0.6371]],
			[[0.7073],[0.9088],[0.5334]],
			[[0.4660],[0.9809],[0.8547]]])
import torch

torch.manual_seed(2)
Tensor_data = torch.rand((3,3,3))
print(Tensor_data)

enc_opt0_min = Tensor_data.min(dim=2)[0].unsqueeze(2) #取最小值张量 索引舍弃
print("min:",enc_opt0_min)
enc_opt0_max = Tensor_data.max(dim=2)[0].unsqueeze(2)
print("max:",enc_opt0_max)

tensor([[[0.6147, 0.3810, 0.6371],
         [0.4745, 0.7136, 0.6190],
         [0.4425, 0.0958, 0.6142]],

        [[0.0573, 0.5657, 0.5332],
         [0.3901, 0.9088, 0.5334],
         [0.7073, 0.7116, 0.2050]],

        [[0.3078, 0.9809, 0.0103],
         [0.4660, 0.4604, 0.8547],
         [0.4525, 0.6317, 0.4760]]])
min: tensor([[[0.3810],[0.4745],[0.0958]],
			[[0.0573],[0.3901],[0.2050]],
			[[0.0103],[0.4604],[0.4525]]])
max: tensor([[[0.6371],[0.7136],[0.6142]],
			[[0.5657],[0.9088],[0.7116]],
			[[0.9809],[0.8547],[0.6317]]])

猜你喜欢

转载自blog.csdn.net/qq_39237205/article/details/130094121