Computer Science/Deep Learning

미래연구소 딥러닝 3주 차 ( Numpy 특강 2)

728x90

미래연구소 http://futurelab.creatorlink.net/

 

미래연구소

AI, 인공지능 Deep Learning beginner 미래연구소 딥러닝 입문 스터디 / 모집인원 : 25명 (선착순 마감) 수강료 : 월 15만원 / (Coursera 강의 수강료 월 5만원 개인결제)

futurelab.creatorlink.net


import numpy as np

 

1) numpy.zeros

원하는 shape에 맞는 영행렬 생성

1d array이면 int 자료형→ np.zeros(3)

2d array이면 tuple 자료형 → np.zeros((3,2))

np.zeros(10)

--출력--
array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0.])
np.zeros((3,2))

--출력--
array([[0. 0],
          [0. 0],
          [0, 0]])

 

2) numpy.exp

x라는 nd array의 원소들을 $e^x$로 바꿔준다.

 

3) numpy.ndarray.shape

X.shape로 호출하고 X라는 nd array의 shape을 return 해준다.

X=np.zeros((3,2))
X.shape

--출력--
(3, 2)

 

4) numpy.arange

case 1: np.arange(stop) → 0부터 시작해서 stop 직전의 수까지 1d array로 만들어진 array

np.arange(12)

--출력--
array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11])

case 2: np.arange(start, stop) → start부터 시작해서 stop 직전의 수까지 1d array로 만들어진 array

np.arange(3,12)

--출력--
array([ 3,  4,  5,  6,  7,  8,  9, 10, 11])

case 3: np.arange(start, stop, step) → start부터 시작해서 stop 직전의 수까지 step씩 증가하는 수를 1d array로 만든다.

np.arange(3,12,3)

--출력--
array([3, 6, 9])

 

5) numpy.ndarray.reshape

X.reshape로 호출하고 X라는 nd array를 내가 원하는 shape에 맞게 재배열해준다.

X=np.arange(12)
X.reshape(2,2,3)

--출력--
array([[[ 0,  1,  2],
           [ 3,  4,  5]],

          [[ 6,  7,  8],
           [ 9, 10, 11]]])

 

6) numpy.sum

x라는 nd array의 원소의 합을 구해준다.

X=np.arange(12)
X.reshape(2,2,3)
X.sum()

--출력--
66

 

7) numpy.ndarray.T

X.T나 np.transpose(X)로 호출한다.(보통 X.T 꼴을 많이 사용한다.

X라는 nd array의 transpose를 구해준다.

X = np.array([[1,2,3,4],[5,6,7,8],[9,10,11,12]])
X1=X.T
X1

--출력--
array([[ 1,  5,  9],
          [ 2,  6, 10],
          [ 3,  7, 11],
          [ 4,  8, 12]])

 

8) numpy.multiply

x1과 x2라는 nd array끼리 element-wise product (위치가 같은 원소끼리 곱셈을 한다.)

x1 = np.array([[1,2,3,4],[5,6,7,8],[9,10,11,12]])
x2 = np.array([[2,2,2,2],[5,5,5,5],[7,7,7,7]])
Y = np.multiply(x1,x2)
Y

--출력--
array([[ 2,  4,  6,  8],
          [25, 30, 35, 40],
          [63, 70, 77, 84]])
728x90