The Y
array in your screenshot is not a 1D array, it's a 2D array with 300 rows and 1 column, as indicated by its shape
being (300, 1)
.
To remove the extra dimension, you can slice the array as Y[:, 0]
. To generally convert an n-dimensional array to 1D, you can use np.reshape(a, a.size)
.
Another option for converting a 2D array into 1D is flatten()
function from numpy.ndarray
module, with the difference that it makes a copy of the array.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…