-
<PYTHON>[Numpy_01 배열 및 자료형]Flower in my dev/Python 2017. 11. 13. 20:17
[Numpy_01 배열 및 자료형]
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556import numpy as npa = [1,2,3,4,5]arr1 = np.array(a) # 배열 생성print(arr1)b = [[1,2,3,4,5],[6,7,8,9,0]]arr2 = np.array(b) # 2차원 배열 생성print(arr2)print(arr1.ndim)print(arr2.ndim)print(arr1.shape)print(arr2.shape)c = [1.1,2.2,3.3]arr3 = np.array(c) # 부동소수점 배열 생성print(arr3)print(arr1.dtype)print(arr3.dtype)arr4 = np.zeros(5) # 0으로 채워진 배열 생성arr5 = np.ones(5) # 1으로 채워진 배열 생성print(arr4)print(arr5)arr6 = np.zeros((2,3))arr7 = np.zeros((2,3,4))print(arr6)print(arr7)arr8 = np.arange(10) # 순차값 배열 생성print(arr8)# 타입을 지정하여 배열 생성
arr1 = np.array([1,2,3], dtype=np.int32)arr2 = np.array([1,2,3], dtype=np.float64)print(arr1.dtype)print(arr2.dtype)# 대상배열의 타입으로 타입 변경
arr3 = arr2.astype(np.int64)print(arr3.dtype)arr4 = np.arange(10)arr5 = np.array([.11, .22], dtype=np.float64)print(arr4.dtype)print(arr5.dtype)arr4.astype(arr5.dtype)print(arr4.dtype)cs - 테스트
'Flower in my dev > Python' 카테고리의 다른 글
<PYTHON>[Numpy_03 불리언&팬시색인] (0) 2017.11.15 <PYTHON>[Numpy_02 배열계산과 색인&슬이싱] (0) 2017.11.14 <PYTHON>[calendar] (0) 2017.07.20 <PYTHON>[단순소스백업] (0) 2017.05.26 <PYTHON>[한줄 for if] (0) 2017.03.31