import numpy as np
x = []
a = np.array([1,2,3])
Out[5]: array([1, 2, 3])
a.shape
Out[6]: (3,)
np.concatenate((x,a))
Out[7]: array([ 1., 2., 3.])
x = np.concatenate((x,a))
x = np.concatenate((x,a))
Out[10]: array([ 1., 2., 3., 1., 2., 3.])
x = []
x = np.concatenate((x,a), axis=1)
=> 오류발생
-. x가 차원이 안맞아서 안됨.
np.expand_dims(a,axis=1)
[2],
[3]])
b = np.expand_dims(a,axis=1)
b.shape
Out[16]: (3, 1)
=> (3,1)짜리 차원으로 확장한 후 열 방향으로 쌓을 수 있다.
=> 아래는 empty함수나 zeros를 사용하여 공간을 만드는 작업
x = []
x = np.empty((3,0))
x
Out[19]: array([], shape=(3, 0), dtype=float64)
x = np.zeros((3,0))
x
Out[21]: array([], shape=(3, 0), dtype=float64)
x = np.zeros((3,0))
a
Out[23]: array([1, 2, 3])
b
Out[24]:
array([[1],
[2],
[3]])
np.concatenate((x,b), axis=1)
Out[26]:
array([[ 1.],
[ 2.],
[ 3.]])
x
Out[27]: array([], shape=(3, 0), dtype=float64)
x = np.concatenate((x,b), axis=1)
x = np.concatenate((x,b), axis=1)
x = np.concatenate((x,b), axis=1)
x
Out[31]:
array([[ 1., 1., 1.],
[ 2., 2., 2.],
[ 3., 3., 3.]])
x = []
=> 차례대로 들어가는 것을 볼 수 있다.
다른 방법으로 ( 이 방법을 더 추천)
-. append로 다 쌓은 후에 for문 밖에서 stack 함수를 사용, vstack과 hstack이 같으나, axis로 컨트롤할 수 있음
a
Out[33]: array([1, 2, 3])
b
Out[34]:
array([[1],
[2],
[3]])
x.append(a)
x.append(a)
x
Out[37]: [array([1, 2, 3]), array([1, 2, 3])]
np.stack(x, axis=1)
Out[38]:
array([[1, 1],
[2, 2],
[3, 3]])
x = []
a = np.array([1,2,3])
Out[5]: array([1, 2, 3])
a.shape
Out[6]: (3,)
np.concatenate((x,a))
Out[7]: array([ 1., 2., 3.])
x = np.concatenate((x,a))
x = np.concatenate((x,a))
Out[10]: array([ 1., 2., 3., 1., 2., 3.])
x = []
x = np.concatenate((x,a), axis=1)
=> 오류발생
-. x가 차원이 안맞아서 안됨.
np.expand_dims(a,axis=1)
Out[14]:
array([[1],[2],
[3]])
b = np.expand_dims(a,axis=1)
b.shape
Out[16]: (3, 1)
=> (3,1)짜리 차원으로 확장한 후 열 방향으로 쌓을 수 있다.
=> 아래는 empty함수나 zeros를 사용하여 공간을 만드는 작업
x = []
x = np.empty((3,0))
x
Out[19]: array([], shape=(3, 0), dtype=float64)
x = np.zeros((3,0))
x
Out[21]: array([], shape=(3, 0), dtype=float64)
x = np.zeros((3,0))
a
Out[23]: array([1, 2, 3])
b
Out[24]:
array([[1],
[2],
[3]])
np.concatenate((x,b), axis=1)
Out[26]:
array([[ 1.],
[ 2.],
[ 3.]])
x
Out[27]: array([], shape=(3, 0), dtype=float64)
x = np.concatenate((x,b), axis=1)
x = np.concatenate((x,b), axis=1)
x = np.concatenate((x,b), axis=1)
x
Out[31]:
array([[ 1., 1., 1.],
[ 2., 2., 2.],
[ 3., 3., 3.]])
x = []
=> 차례대로 들어가는 것을 볼 수 있다.
다른 방법으로 ( 이 방법을 더 추천)
-. append로 다 쌓은 후에 for문 밖에서 stack 함수를 사용, vstack과 hstack이 같으나, axis로 컨트롤할 수 있음
Out[33]: array([1, 2, 3])
b
Out[34]:
array([[1],
[2],
[3]])
x.append(a)
x.append(a)
x
Out[37]: [array([1, 2, 3]), array([1, 2, 3])]
np.stack(x, axis=1)
Out[38]:
array([[1, 1],
[2, 2],
[3, 3]])
댓글
댓글 쓰기