【发布时间】:2015-03-01 05:42:06
【问题描述】:
我在一个正在运行的程序中间有一个 numpy 矩阵(假设它的名字是rdy)。我发现将它重塑为一维矩阵给了我一个二维矩阵。但是如果我在交互式 shell 中尝试同样的事情,我会得到预期的结果。就像下面的 ipython 日志一样。我想知道矩阵 rdy 的哪个方面导致它在重塑时表现不同?
# This is expected:
In [191]: np.random.rand(512, 1).reshape(-1).shape
Out[191]: (512,)
# This is unexpected:
In [192]: rdy.reshape(-1).shape
Out[192]: (1, 512)
# The following are the different aspects of the rdy matrix:
In [193]: rdy.shape
Out[193]: (512, 1)
In [194]: rdy.flags
Out[194]:
C_CONTIGUOUS : True
F_CONTIGUOUS : False
OWNDATA : False
WRITEABLE : True
ALIGNED : True
UPDATEIFCOPY : False
In [195]: rdy.data
Out[195]: <read-write buffer for 0xeae6488, size 4096, offset 0 at 0x2ff95e70>
【问题讨论】: