#对列表中的元素是tensor形式,取出后在进行合并的代码块
import torch
import torch.nn as nn
import numpy as np
v= torch.rand(1,3,5,5)
a = torch.rand(1,3,5,5)
g = torch.rand(1,3,5,5)
print('v = ',v)
print('a = ',a)
print('g = ',g)
cc = [v,a,g]
print('cc =',cc)
# print('cc =',cc[0][0])
kk = cc[0]
for i in range(1,3):
kk =torch.cat([kk,cc[i]],dim=1)
print('kk = ',kk)
输出:
v = tensor([[[[0.6059, 0.3054, 0.5200, 0.5751, 0.1770],
[0.0119, 0.3483, 0.7714, 0.8116, 0.4110],
[0.0721, 0.7408, 0.2906, 0.1604, 0.3585],
[0.3620, 0.9603, 0.5209, 0.2113, 0.4210],
[0.8271, 0.0126, 0.5542, 0.4912, 0.3096]],
[[0.0705, 0.7614, 0.1113, 0.8989, 0.7568],
[0.2034, 0.3129, 0.4130, 0.4895, 0.8762],
[0.2438, 0.3747, 0.3034, 0.7641, 0.1040],
[0.7863, 0.1884, 0.7428, 0.7889, 0.6837],
[0.6977, 0.5085, 0.7210, 0.6363, 0.7057]],
[[0.0628, 0.6271, 0.3749, 0.2456, 0.5753],
[0.9370, 0.0462, 0.3693, 0.1685, 0.7179],
[0.2888, 0.1039, 0.2867, 0.2473, 0.4370],
[0.4085, 0.0895, 0.9019, 0.3055, 0.5997],
[0.7072, 0.0653, 0.8974, 0.9605, 0.0515]]]])
a = tensor([[[[0.5081, 0.2016, 0.3595, 0.5647, 0.6166],
[0.1537, 0.1610, 0.4695, 0.7655, 0.2025],
[0.7134, 0.4207, 0.3419, 0.4681, 0.7792],
[0.8102, 0.2134, 0.8475, 0.5760, 0.6482],
[0.8896, 0.5883, 0.1221, 0.5238, 0.3383]],
[[0.8911, 0.4325, 0.0665, 0.5608, 0.6368],
[0.6696, 0.0119, 0.7177, 0.2349, 0.9821],
[0.1365, 0.2518, 0.2800, 0.0642, 0.8160],
[0.8505, 0.2082, 0.0993, 0.3335, 0.0956],
[0.6343, 0.5207, 0.0191, 0.7632, 0.9919]],
[[0.7351, 0.6021, 0.0938, 0.7139, 0.6526],
[0.6404, 0.3496, 0.4939, 0.8169, 0.8686],
[0.9611, 0.7747, 0.1785, 0.2085, 0.9276],
[0.9635, 0.2078, 0.6476, 0.7075, 0.4646],
[0.1031, 0.1586, 0.1619, 0.5944, 0.1751]]]])
g = tensor([[[[0.2943, 0.6919, 0.1296, 0.2068, 0.1996],
[0.8720, 0.8587, 0.8966, 0.1579, 0.7721],
[0.6064, 0.9321, 0.1933, 0.6299, 0.2137],
[0.5715, 0.5817, 0.3618, 0.5065, 0.9580],
[0.5033, 0.6510, 0.8061, 0.8505, 0.7614]],
[[0.9084, 0.6394, 0.9369, 0.6663, 0.1645],
[0.8052, 0.4574, 0.5348, 0.9387, 0.8689],
[0.5024, 0.3764, 0.2366, 0.3683, 0.8779],
[0.3009, 0.2337, 0.1286, 0.9421, 0.6681],
[0.8073, 0.3271, 0.4459, 0.7707, 0.5065]],
[[0.1283, 0.7590, 0.8975, 0.7848, 0.9386],
[0.8646, 0.3976, 0.4809, 0.0489, 0.1203],
[0.5841, 0.7714, 0.8688, 0.4576, 0.5153],
[0.6509, 0.2691, 0.0931, 0.3019, 0.3734],
[0.7895, 0.6699, 0.0211, 0.1625, 0.4616]]]])
cc = [tensor([[[[0.6059, 0.3054, 0.5200, 0.5751, 0.1770],
[0.0119, 0.3483, 0.7714, 0.8116, 0.4110],
[0.0721, 0.7408, 0.2906, 0.1604, 0.3585],
[0.3620, 0.9603, 0.5209, 0.2113, 0.4210],
[0.8271, 0.0126, 0.5542, 0.4912, 0.3096]],
[[0.0705, 0.7614, 0.1113, 0.8989, 0.7568],
[0.2034, 0.3129, 0.4130, 0.4895, 0.8762],
[0.2438, 0.3747, 0.3034, 0.7641, 0.1040],
[0.7863, 0.1884, 0.7428, 0.7889, 0.6837],
[0.6977, 0.5085, 0.7210, 0.6363, 0.7057]],
[[0.0628, 0.6271, 0.3749, 0.2456, 0.5753],
[0.9370, 0.0462, 0.3693, 0.1685, 0.7179],
[0.2888, 0.1039, 0.2867, 0.2473, 0.4370],
[0.4085, 0.0895, 0.9019, 0.3055, 0.5997],
[0.7072, 0.0653, 0.8974, 0.9605, 0.0515]]]]), tensor([[[[0.5081, 0.2016, 0.3595, 0.5647, 0.6166],
[0.1537, 0.1610, 0.4695, 0.7655, 0.2025],
[0.7134, 0.4207, 0.3419, 0.4681, 0.7792],
[0.8102, 0.2134, 0.8475, 0.5760, 0.6482],
[0.8896, 0.5883, 0.1221, 0.5238, 0.3383]],
[[0.8911, 0.4325, 0.0665, 0.5608, 0.6368],
[0.6696, 0.0119, 0.7177, 0.2349, 0.9821],
[0.1365, 0.2518, 0.2800, 0.0642, 0.8160],
[0.8505, 0.2082, 0.0993, 0.3335, 0.0956],
[0.6343, 0.5207, 0.0191, 0.7632, 0.9919]],
[[0.7351, 0.6021, 0.0938, 0.7139, 0.6526],
[0.6404, 0.3496, 0.4939, 0.8169, 0.8686],
[0.9611, 0.7747, 0.1785, 0.2085, 0.9276],
[0.9635, 0.2078, 0.6476, 0.7075, 0.4646],
[0.1031, 0.1586, 0.1619, 0.5944, 0.1751]]]]), tensor([[[[0.2943, 0.6919, 0.1296, 0.2068, 0.1996],
[0.8720, 0.8587, 0.8966, 0.1579, 0.7721],
[0.6064, 0.9321, 0.1933, 0.6299, 0.2137],
[0.5715, 0.5817, 0.3618, 0.5065, 0.9580],
[0.5033, 0.6510, 0.8061, 0.8505, 0.7614]],
[[0.9084, 0.6394, 0.9369, 0.6663, 0.1645],
[0.8052, 0.4574, 0.5348, 0.9387, 0.8689],
[0.5024, 0.3764, 0.2366, 0.3683, 0.8779],
[0.3009, 0.2337, 0.1286, 0.9421, 0.6681],
[0.8073, 0.3271, 0.4459, 0.7707, 0.5065]],
[[0.1283, 0.7590, 0.8975, 0.7848, 0.9386],
[0.8646, 0.3976, 0.4809, 0.0489, 0.1203],
[0.5841, 0.7714, 0.8688, 0.4576, 0.5153],
[0.6509, 0.2691, 0.0931, 0.3019, 0.3734],
[0.7895, 0.6699, 0.0211, 0.1625, 0.4616]]]])]
kk = tensor([[[[0.6059, 0.3054, 0.5200, 0.5751, 0.1770],
[0.0119, 0.3483, 0.7714, 0.8116, 0.4110],
[0.0721, 0.7408, 0.2906, 0.1604, 0.3585],
[0.3620, 0.9603, 0.5209, 0.2113, 0.4210],
[0.8271, 0.0126, 0.5542, 0.4912, 0.3096]],
[[0.0705, 0.7614, 0.1113, 0.8989, 0.7568],
[0.2034, 0.3129, 0.4130, 0.4895, 0.8762],
[0.2438, 0.3747, 0.3034, 0.7641, 0.1040],
[0.7863, 0.1884, 0.7428, 0.7889, 0.6837],
[0.6977, 0.5085, 0.7210, 0.6363, 0.7057]],
[[0.0628, 0.6271, 0.3749, 0.2456, 0.5753],
[0.9370, 0.0462, 0.3693, 0.1685, 0.7179],
[0.2888, 0.1039, 0.2867, 0.2473, 0.4370],
[0.4085, 0.0895, 0.9019, 0.3055, 0.5997],
[0.7072, 0.0653, 0.8974, 0.9605, 0.0515]],
[[0.5081, 0.2016, 0.3595, 0.5647, 0.6166],
[0.1537, 0.1610, 0.4695, 0.7655, 0.2025],
[0.7134, 0.4207, 0.3419, 0.4681, 0.7792],
[0.8102, 0.2134, 0.8475, 0.5760, 0.6482],
[0.8896, 0.5883, 0.1221, 0.5238, 0.3383]],
[[0.8911, 0.4325, 0.0665, 0.5608, 0.6368],
[0.6696, 0.0119, 0.7177, 0.2349, 0.9821],
[0.1365, 0.2518, 0.2800, 0.0642, 0.8160],
[0.8505, 0.2082, 0.0993, 0.3335, 0.0956],
[0.6343, 0.5207, 0.0191, 0.7632, 0.9919]],
[[0.7351, 0.6021, 0.0938, 0.7139, 0.6526],
[0.6404, 0.3496, 0.4939, 0.8169, 0.8686],
[0.9611, 0.7747, 0.1785, 0.2085, 0.9276],
[0.9635, 0.2078, 0.6476, 0.7075, 0.4646],
[0.1031, 0.1586, 0.1619, 0.5944, 0.1751]],
[[0.2943, 0.6919, 0.1296, 0.2068, 0.1996],
[0.8720, 0.8587, 0.8966, 0.1579, 0.7721],
[0.6064, 0.9321, 0.1933, 0.6299, 0.2137],
[0.5715, 0.5817, 0.3618, 0.5065, 0.9580],
[0.5033, 0.6510, 0.8061, 0.8505, 0.7614]],
[[0.9084, 0.6394, 0.9369, 0.6663, 0.1645],
[0.8052, 0.4574, 0.5348, 0.9387, 0.8689],
[0.5024, 0.3764, 0.2366, 0.3683, 0.8779],
[0.3009, 0.2337, 0.1286, 0.9421, 0.6681],
[0.8073, 0.3271, 0.4459, 0.7707, 0.5065]],
[[0.1283, 0.7590, 0.8975, 0.7848, 0.9386],
[0.8646, 0.3976, 0.4809, 0.0489, 0.1203],
[0.5841, 0.7714, 0.8688, 0.4576, 0.5153],
[0.6509, 0.2691, 0.0931, 0.3019, 0.3734],
[0.7895, 0.6699, 0.0211, 0.1625, 0.4616]]]])