12 Jul 2020
Numpy Array 기본 함수
Numpy basic function
import numpy as np
arr1 = np.array([[1.0,2,3],[4,5,6]], dtype=np.int32)
print(arr1)
'''
[[1 2 3]
[4 5 6]]
'''
type(ndarray)
import numpy as np
print(type(arr1))
'''
<class 'numpy.ndarray'>
--> 데이터 타입을 출력
'''
ndim(ndarray)
import numpy as np
print(np.ndim(arr1))
'''
2 --> 데이터의 dimension
'''
shape(ndarray)
import numpy as np
print(np.shape(arr1))
'''
(2, 3) --> 데이터의 형식 (2행 3열)
'''
size(ndarray)
import numpy as np
print(np.size(arr1))
'''
6 --> 데이터의 크기
'''
arange(start, end, step)
import numpy as np
arr = np.arange(0,32,2)
print(arr)
'''
[ 0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30] -->2간격으로, 0부터 32사이
'''
reshape(row, col)
import numpy as np
arr2 = np.arange(32).reshape(4,8)
print(arr2)
'''
[[ 0 1 2 3 4 5 6 7]
[ 8 9 10 11 12 13 14 15]
[16 17 18 19 20 21 22 23]
[24 25 26 27 28 29 30 31]]
'''
astype(np.dtype)
import numpy as np
arr1 = np.array([[1.0,2,3],[4,5,6]], dtype=np.int32)
arr1_1 = arr1.astype(np.float64)
print(arr1_1)
print(type(arr1_1))
'''
[[1. 2. 3.]
[4. 5. 6.]] -> int32 > float64
<class 'numpy.ndarray'>
'''
Tags: