|  | 
	Numpy
	
		Numerical Pythonimport numpy as np다차원배열(n(multi)-dimensional array)
	
		http://rfriend.tistory.com/283?category=675917빠른 처리속도np.array() -> ndarray(multi-dimensional array)
np.asarray()np.asfarray()np.asarray_chkfinite()
np.zeros()np.ones()np.empty()np.zeros_like()np.ones_like()np.empty_like()
np.arrange()np.identity()np.eye()NumPy의 array() 로 ndarray 를 
		
			import numpy as nparr1=np.array([1, 2, 3, 4, 5]) # making a arraylist 객체를 먼저 만들고 np.array() 를 사용해서 배열로 변환해도 됩니다. 
		
			data_list = [6, 7, 8, 9, 10] # making a listarr2 = np.array(data_list) # converting a list into an array같은 길이의 여러개의 리스트(lists)를 가지고 있는 리스트(a list)도 np.array()를 사용해서 배열(array)로 변환할 수 있습니다. 
		
			data_lists = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]] # a list of equal-length listsarr12 = np.array(data_lists) #converting a list of equal-length lists into a multi-dimensional arrayarr12 array([[ 1,  2,  3,  4,  5],
 [ 6,  7,  8,  9, 10]])
ndarray obj.shape 함수 : ndarray의 차원 원소 수 점검
		
			arr12.shape  # (2,5) a tuple indicating the size of each dimension
			
				arr12.shape[0]  # 2arr12.shape[1]  # 5arr12.dtype     # dtype('int32') list,ndarray 변환
		
			plst=[1,2]           # python listnarr=np.asarray(plst)  #converting :  python  list => numpy.ndarraynarr_1=np.asarray(nlst)  # narr is narr_1 => true 복사하지 않는다.,  동일한 데이형narr_2=np.array(nlst)  # narr is narr_1 => False 복사한다. 동일해도 복사np.asarray(narr, dtype=np.int32) is narr #True  Not copyed(Shllow copyed)# narr은 int32형이다.
np.asarray(narr, dtype=np.int64) is narr #False copyed(Deep copyed) 다른형narr_f=np.asfrray(narr) # == np.asarray(narr, dtype=np.float64)np.asarray_chkfinite(plst, dtype=float)[1., 3.] #원소에 결함원소를 점검 없으면 정상변환
np.asarray_chkfinite([1,2,np.nan], dtype=float) #있으면 오류메세지ValueError: array must not contain infs or NaNs
np.asarray_chkfinite([1,2,np.inf], dtype=float) #무한값이 있으면 오류메세지ValueError: array must not contain infs or NaNs
np.zeros(), np.ones(), np.empty() 함수는 괄호 안에 쓴 숫자 개수만큼의 '0', '1', '비어있는 배열', np.zeros((2, 5)), np.ones((5, 3)), np.empty((4, 3)) 처럼 괄호 안에 tuple을 넣어주면 다차원 배열
		
			np.zeros(5) #array([ 0., 0., 0., 0., 0.])np.ones(5) #array([ 1., 1., 1., 1., 1.])np.empty(5) #array([ 0., 0., 0., 0., 0.]) empty valuesnp.zeros((2, 5))array([[ 0.,  0.,  0.,  0.,  0.],
 [ 0.,  0.,  0.,  0.,  0.]])
np.arange() 는 Python의 range() 함수처럼 0부터 괄호안의 숫자 만큼의 정수 배열 값을 '배열'로 
		
			f = np.arange(10) #array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])  cf. python rnagenp.zeros_like(), np.ones_like(), np.empty_like() 함수는 이미 있는 array와 동일한 모양과 데이터 형태를 유지
		
			f25=f.reshape(2,5))ararray([[0, 1, 2, 3, 4],
 [5, 6, 7, 8, 9]])
np.zeros_like(f_2_5) array([[0, 0, 0, 0, 0],
 [0, 0, 0, 0, 0]])
np.ones_like(f_2_5) array([[1, 1, 1, 1, 1],
 [1, 1, 1, 1, 1]])
np.empty_like(f_2_5) array([[0, 0, 0, 0, 0],
 [0, 0, 0, 0, 0]])
항등행렬(identity matrix), 단위행렬(unit matrix)  http://rfriend.tistory.com/141
		
			np.identity(3)array([[ 1.,  0.,  0.,],
 [ 0.,  1.,  0.,],
 [ 0.,  0.,  1.,]])
np.eye(3)array([[ 1.,  0.,  0.,],
 [ 0.,  1.,  0.,],
 [ 0.,  0.,  1.,]])
data type변환
		
		Numpy Data Type  http://rfriend.tistory.com/285
	
		Data Type
		
			Boolean, Integer, Unsigned Integer, Float, Complex, StringOperations
		
			Assigning Data Type
			
				np.array[xx,xx], dtype=np.Type)np.array([xx, xx], dtype=np.'Type Code')Checking Data Type
			
			Converting Data Type
			
			Examples of a array [1.4, 2.6, 3.0 with data type pf float64:np.float64()
		
			import numpy as np# np.array[xx,xx],  np.array[xx,xx],np.float64), # np.array[xx,xx],np.'type code')x_float64 = np.array([1.4, 2.6, 3.0]  x_float64_1 = np.array([1.4, 2.6, 3.0, 4.9, 5.32], dtype=np.float64)x_float64_2 = np.array([1.4, 2.6, 3.0, 4.9, 5.32], dtype=np.'f8'x_float64.dtype   # Checking typedtype('float64')
x_float64                                   # checking coententarray([ 1.4 , 2.6 , 3. ])
x_int64=x_float64.astype(np.int64) # Convert flaot64 to int645 the decimal parts are truncatedx_int64_2 = np.int64(x_float64)x_int64.dtypedtype('int64')
x_int64_2array([1, 2, 3], dtype=int64)
......http://rfriend.tistory.com/285 |  |