numpy重塑功能.这两行代码有何不同



这两行代码有何不同:

X_flatten = X.reshape(X.shape[0], -1).T
X_flatten = X.reshape(-1, X.shape[0])

这两行的输出不同,与彼此无关的看看这个示例:假设X就像以下内容:

>>> X = np.arange(6).reshape(2,3)
>>> X
array([[0, 1, 2],
       [3, 4, 5]])

第一行输出:

>>> X_flatten = X.reshape(X.shape[0], -1).T
>>> X_flatten
array([[0, 3],
       [1, 4],
       [2, 5]])

,第二行输出为:

>>> X_flatten = X.reshape(-1, X.shape[0])
>>> X_flatten
array([[0, 1],
       [2, 3],
       [4, 5]])

最新更新