NumPy : 과학 컴퓨팅을 위한 기본 패키지
Numpy 패키지의 핵심은 ndarray 객체이다
ndarray - fixed-size homogeneous multitdimensional array, vectorization 과 broadcasting 을 지원한다
동일한 데이터 타입만 요소로 가질 수 있으며, 크기는 고정되어 있다 > 속도 향상을 위함
list, tuple 은 서로 다른 데이터 타입을 저장할 수 있는 heterogeneous sequence 이다
ndarray 는 list 나 tuple 같은 시퀀스 자료형으로부터 만든다
import numpy as np
x = np.array([1,2,3,4])
y = np.array([1,2,3,4], dtype='float64') # type 지정
x.shape
x.dtype
1차원 배열의 shape 는 (m,) 형태, 2차원 배열의 형태는 (m,n) 형태
x.ndim 은 len(x.shape) 와 동일함 : 차원수
초기값 지정
x = np.zeros((2,2))
y = np.ones((2,2), dtype='int32')
z = np.empty((2,2))
단순한 시퀀스 만들기
A = np.array([])
for i in range(2):
A = np.appen(A,[1,2])
np.arange(1,2,0.2)
np.arange(10)
np.arange(10.)
np.linspace(0.,20.,11)
np.eye(2)
shape 변경하기
x = np.arange(0,9,1)
y = np.reshape(x, (3,3))
x.shpae(3,3)
dtype 변경하기
a = np.arange(5)
a.astype(int)
a.astype('int32')
3.1 ndarray
### 개념과 생성 NumPy와 패키지의 핵심은 `ndarray` 객체이다. * `ndarray`는 fixed-size homogeneous multidimension ...
wikidocs.net