我目前正在使用 PyTorch 框架并试图理解外国代码。我遇到了索引问题,想打印列表的形状。
这样做的唯一方法(据 Google 告诉我)是将列表转换为 numpy 数组,然后使用 numpy.ndarray.shape() 获取形状。
但是尝试将我的列表转换为数组时,我得到了一个ValueError: only one element tensors can be converted to Python scalars
.
我的列表是一个转换后的 PyTorch Tensor ( list(pytorchTensor)
),看起来有点像这样:
[张量([[-0.2781, -0.2567, -0.2353, ..., -0.9640, -0.9855, -1.0069],
[-0.2781, -0.2567, -0.2353, ..., -1.0069, -1.02083] ],
[-0.2567, -0.2567, -0.2138, ..., -1.0712, -1.1141, -1.1784],
...,
[-0.6640, -0.6425, -0.6211, ..., -1.0712, -1.11114] -1.0927],
[-0.6640, -0.6425, -0.5997, ..., -0.9426, -0.9640, -0.9640],
[-0.6640, -0.6425, -0.5997, ..., -0.9640, -0.9640, -26, -26 ]]), 张量([[-0.0769, -0.0980, -0.076 9, ..., -0.9388, -0.9598, -0.9808],
[-0.0559, -0.0769, -0.0980, ..., -0.9598 1.0018, -1.0228],
[-0.0559, -0.0769, -0.0769, ..., -1.0228, -1.0439, -1.0859],
...,
[-0.4973,-0.4973,-0.4973,...,-1.0018,-1.0439,-1.0228],
[-0.4973,-0.4973,-0.4973,...,-0.8757,-0.9177,-0.9177],
[ - 0.4973, -0.4973, -0.4973, ..., -0.9177, -0.8967, -0.8967]]), 张量([[-0.1313, -0.1313, -0.110 0, ..., -0.8115, -8,0.3. ],
[-0.1313, -0.1525, -0.1313, ..., -0.8541, -0.8966, -0.9391],
[-0.1100, -0.1313, -0.1100, ..., -0.9391, -, -0.9816]
...,
[-0.4502, -0.4714, -0.4502, ..., -0.8966, -0.8966, -0.8966],
[-0.4502, -0.4714, -0.4502, ..., -0.8115, -0.81709,3 ],
[-0.4502, -0.4714, -0.4502, ..., -0.8115, -0.7690, -0.7690]])]
有没有办法在不将其转换为 numpy 数组的情况下获取该列表的形状?
回首忆惘然
RISEBY
相关分类