数字:3D到2D

2024-06-01 05:56:58 发布

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

我有一个形状为[2000, 140, 190]的矩阵。这里,2000是二维切片的数量,其中每个切片是[140190]。在

我想把这个3D矩阵转换成[7000, 7600](提示:140*50 = 7000190*40 = 760050*40 = 2000)。我想扩展矩阵的行主要时尚。有什么建议吗?在


Tags: 数量切片矩阵时尚建议形状
3条回答

如评论中所述,您可以np.reshape

m_2d = np.random.rand(7000, 7600)
m_3d = m_2d.reshape([2000, 140, 190])

解决方案是reshape,如果您想要row major,那么根据文档,您应该将order设置为F

m_2d = np.random.rand(7000, 7600)
m_3d = m_2d.reshape([2000, 140, 190],order='F')

听起来你也想要一个转置:

m_3d = np.random.rand(2000, 140, 190)

# break the 2000 dimension in two. Pick one:
m_4d = m_3d.reshape((50, 40, 140, 190))

# move the dimensions to collapse to be adjacent
# you might need to tweak this - you haven't given enough information to know
# what order you want
m_4d = m_4d.transpose((0, 2, 1, 3))

# collapse adjacent dimensions
m_2d = m_4d.reshape((7000, 7600))

相关问题 更多 >