# numpy.c_ (column bind)와 numpy_r(row bind)의 비교
a = np.array([1, 2, 3])
b = np.array([4, 5, 6])
print(a, type(a), a.shape)
print(b, type(b), b.shape)
[1 2 3] <class 'numpy.ndarray'> (3,)
[4 5 6] <class 'numpy.ndarray'> (3,)
c = np.c_[a, b]
print(c, type(c), c.shape)
[[1 4]
[2 5]
[3 6]] <class 'numpy.ndarray'> (3, 2)
d = np.r_[a, b]
print(d, type(d), d.shape)
[1 2 3 4 5 6] <class 'numpy.ndarray'> (6,)
e = np.r_[[a], [b]]
print(e, type(e), e.shape)
[[1 2 3]
[4 5 6]] <class 'numpy.ndarray'> (2, 3)
f = np.array([[1, 2, 3],
[4, 5, 6]])
g = np.array([[10, 20],
[30, 40]])
row 개수가 같아야 column 방향으로 붙일 수 있음.
h = np.c_[f, g]
print(h, type(h), h.shape)
[[ 1 2 3 10 20]
[ 4 5 6 30 40]] <class 'numpy.ndarray'> (2, 5)
column 개수가 같아야 row 방향으로 붙일 수 있음.
i = np.array([[10, 20, 30],
[30, 40, 50]])
j = np.r_[f, i]
print(j, type(j), j.shape)
[[ 1 2 3]
[ 4 5 6]
[10 20 30]
[30 40 50]] <class 'numpy.ndarray'> (4, 3)
k = np.array([1, 2, 3])
print(np.r_[i, [k]])
[[10 20 30]
[30 40 50]
[ 1 2 3]]
'Python > Python기초' 카테고리의 다른 글
numpy.mean, numpy.std의 axis 알아보기 (0) | 2020.07.20 |
---|---|
Python 76_ iris 데이터를 이용한 Logistic 함수 적용 (0) | 2020.03.09 |
Python 75_ Logistic (sigmoid) 함수 (0) | 2020.03.06 |
Python 74_ Logistic Regression 로지스틱 회귀 (0) | 2020.03.05 |
Python 73_ seaborn 패키지 이용한 시각화 ( load_boston 활용 ) (0) | 2020.03.04 |
# numpy.c_ (column bind)와 numpy_r(row bind)의 비교
a = np.array([1, 2, 3])
b = np.array([4, 5, 6])
print(a, type(a), a.shape)
print(b, type(b), b.shape)
[1 2 3] <class 'numpy.ndarray'> (3,)
[4 5 6] <class 'numpy.ndarray'> (3,)
c = np.c_[a, b]
print(c, type(c), c.shape)
[[1 4]
[2 5]
[3 6]] <class 'numpy.ndarray'> (3, 2)
d = np.r_[a, b]
print(d, type(d), d.shape)
[1 2 3 4 5 6] <class 'numpy.ndarray'> (6,)
e = np.r_[[a], [b]]
print(e, type(e), e.shape)
[[1 2 3]
[4 5 6]] <class 'numpy.ndarray'> (2, 3)
f = np.array([[1, 2, 3],
[4, 5, 6]])
g = np.array([[10, 20],
[30, 40]])
row 개수가 같아야 column 방향으로 붙일 수 있음.
h = np.c_[f, g]
print(h, type(h), h.shape)
[[ 1 2 3 10 20]
[ 4 5 6 30 40]] <class 'numpy.ndarray'> (2, 5)
column 개수가 같아야 row 방향으로 붙일 수 있음.
i = np.array([[10, 20, 30],
[30, 40, 50]])
j = np.r_[f, i]
print(j, type(j), j.shape)
[[ 1 2 3]
[ 4 5 6]
[10 20 30]
[30 40 50]] <class 'numpy.ndarray'> (4, 3)
k = np.array([1, 2, 3])
print(np.r_[i, [k]])
[[10 20 30]
[30 40 50]
[ 1 2 3]]
'Python > Python기초' 카테고리의 다른 글
numpy.mean, numpy.std의 axis 알아보기 (0) | 2020.07.20 |
---|---|
Python 76_ iris 데이터를 이용한 Logistic 함수 적용 (0) | 2020.03.09 |
Python 75_ Logistic (sigmoid) 함수 (0) | 2020.03.06 |
Python 74_ Logistic Regression 로지스틱 회귀 (0) | 2020.03.05 |
Python 73_ seaborn 패키지 이용한 시각화 ( load_boston 활용 ) (0) | 2020.03.04 |