使用 (-1,1) 重塑 numpy 中的数据。这是什么意思?

rul*_*tra 4 numpy-ndarray

我从 /sf/answers/4019251841/得到了什么np.reshape(-1)。它将其重塑为一维数组。但是 (a,(-1,1)) 呢?

a_concat = np.reshape(a,(-1,1))
Run Code Online (Sandbox Code Playgroud)

Dem*_*une 16

reshape(-1)是线向量,当reshape(-1,1)是列向量时:

>>> import numpy as np
>>> a = np.linspace(1,6,6).reshape(2,3)
>>> a
array([[ 1.,  2.,  3.],
       [ 4.,  5.,  6.]])
>>> a.shape
(2, 3)
>>> a.reshape(-1)
array([ 1.,  2.,  3.,  4.,  5.,  6.])
>>> a.reshape(-1,1)
array([[ 1.],
       [ 2.],
       [ 3.],
       [ 4.],
       [ 5.],
       [ 6.]])
Run Code Online (Sandbox Code Playgroud)