我需要一段python的pytorch版本代码,四维列表和二维列表变成矩阵,四维矩阵最后一维的尺寸为5与二维矩阵的行和列尺寸为5,四维矩阵的最后一维单独乘以二维矩阵,其他维度数据不变...

import torch list_4d = torch.rand(4, 5, 5, 5) list_2d = torch.rand(5, 5) list_4d[..., -1] = list_4d[..., -1] * list_2d matrix_4d = torch.sum(list_4d, dim=-1)

猜你喜欢

转载自blog.csdn.net/weixin_35757191/article/details/129609953