Numpy和数组形状

2024-04-26 17:34:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个多维数组,我想形状为(19381100,6)。一旦我将数组转换为numpy数组,我得到的形状就是(19381,)

Input: d.shape
Output: (19381,)
Input: d[0].shape
Output: (100,6)
Input: d[0][0].shape
Output: (6,)
Input: if any(i.shape != (100,6) for i in d):
           print(True)
       else:
           print(False)
Output: False

我错过了什么?我试过使用

d.shape = (19381,100,6)

但是我得到一个“无法将19381大小的数组重塑为形状(19381100,6)

谢谢你

伊恩


Tags: innumpyfalsetrueforinputoutputif
1条回答
网友
1楼 · 发布于 2024-04-26 17:34:35

出现这个问题是因为我创建numpy数组的方式。我想做些

l1 = [1,2,3,4]
l2 = [5,6,7,8]
l = zip(l1, l2)
np.random.shuffle(l)
l1, l2 = np.array(zip(*l))

一旦我把密码改成

l1, l2 = zip(*l)
l1 = np.array(l1)
l2 = np.array(l2)

形状输出与预期一致。你知道吗

相关问题 更多 >