我正在运行一个程序,其中有一个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>
asparse.A
或asparse.toarray()
从稀疏矩阵中生成数组。 - hpaulj