데이터 분석/NumPy

파이썬 데이터사이언스 핸드북 2 장 - ndarray 소개

haloaround 2020. 5. 16. 09:24

NumPy 는 조밀한 데이터 버퍼에서 저장하고 처리하는 효과적인 이터페이스를 제공한다. NumPy 배열은 파이썬 내장타입인 list 와 비슷하지만 배열의 규모가 커질수록 데이터 저장 및 처리에 훨씬 더 효율적이다. NumPy 배열은 파이썬의 데이터 과학 도구로 구성된 전체 생태계의 핵심을 이루고 있기 때문에 관심있는 데이터 과학 측면이 무엇이든 상관없이 NumPy 를 효과적으로 사용하는 법을 배워야한다.


numpy.ndarray

numpy.ndarray

 

ndarray docstrings

ndarray(shape, dtype=float, buffer=None, offset=0, strides=None, order=None)

 

 

ndarray definition

An array object represents a multidimensional, homogeneous array of fixed-size items.
다차원의, 동일한 데이터타입의 아이템으로 채워진, 고정된 사이즈의  배열

 

ndarray attributes

np.shape 배열의 다차원 형태 multidimensional

np.dtype  배열 내부 아이템의 데이터타입 homogenous

 

 

 

 

ndarry creation

규모가 큰 배열의 경우에는 NumPy 에 내장된 루틴을 사용해서 처음부터 배열을 생성하는 것이 더 효율적이다.

 

np.array ([1,2,3,4,5])

The parameters given here refer to a low-level method of ndarray for instantiating an array

단순하게 배열에 들어가는 값을 직접 지정할 수 있다. 

 

np.zeros((2,2), dtype=int)

Arrays should be constructed using `array`, `zeros`, or `empty`

또는 numpy 의 함수를 활용하여 배열을 생성할 수 있다. numpy 는 배열을 생성하기 위한 다양한 함수를 제공한다. 

0,  1로 채우거나, 데이터가 이미 있을 경우 그 값들로 채우거나 숫자 연산을 통해서 채우거나  랜덤 숫자로 채울 수도 있다. 

 

다양한 방식은 여기에서: https://www.w3resource.com/numpy/array-creation/index.php

 

NumPy Array creation - w3resource

NumPy Array Creation: NumPy’s main object is the homogeneous multidimensional array. It is a table of elements (usually numbers), all of the same type, indexed by a tuple of positive integers - w3resource

www.w3resource.com