Difference between python np.array shape (n,) and (n,1)

(n,)

1
2
3
4
import numpy as np
shape_demo = np.array([1,2,3,4])
print(shape_demo)
print(shape_demo.shape)

(n,1)

1
2
3
shape_demo_1 = np.array([[1],[2],[3],[4]])
print(shape_demo_1)
print(shape_demo_1.shape)

(2,4)

1
2
3
shape_demo_2 = np.array([[1,2,3,4],[5,6,7,8]])
print(shape_demo_2)
print(shape_demo_2.shape)

sklearn datasets.make_regression

1
2
3
4
5
6
import matplotlib.pyplot as plt
import numpy
from sklearn import datasets

#n_samples=10 n_features=1
regressionData = datasets.make_regression(10, 1, noise=10)

type of regressionData is tuple(2 items)
(ndarray with shape (10, 1), ndarray with shape (10,))

1
type(regressionData)


1
regressionData[0]


1
regressionData[1]

ref [Day27]機器學習:建立線性迴歸資料與預測!
ref numpy.array 的shape属性理解
ref python 里 np.array 的shape ( ,)与( ,1)的区别