728x90
Array 생성
In [19]:
#string type의 데이터를 입력해도 float type으로 자동 형변환
test_array = np.array(["1", "4", 5, 8], float)
test_array
Out[19]:
In [20]:
type(test_array[3])
Out[20]:
In [21]:
test_array = np.array([1, 4, 5, "8"], np.float32)
test_array
Out[21]:
In [22]:
type(test_array[3])
Out[22]:
In [23]:
#array 전체의 데이터 type을 반환
test_array.dtype
Out[23]:
In [26]:
np.array([[1, 4, 5, "8"]], np.float32).shape
Out[26]:
In [28]:
test_array.shape
Out[28]:
Array Shape
In [30]:
vector = [1,2,3,4]
np.array(vector, int).shape
Out[30]:
In [32]:
matrix = [[1,2,5,8],[1,2,5,8], [1,2,5,8]]
np.array(matrix, int).shape
Out[32]:
In [34]:
tensor = [[[1,2,5,8],[1,2,5,8],[1,2,5,8]],
[[1,2,5,8], [1,2,5,8], [1,2,5,8]],
[[1,2,5,8], [1,2,5,8], [1,2,5,8]],
[[1,2,5,8], [1,2,5,8], [1,2,5,8]]]
np.array(tensor, int).shape
Out[34]:
In [36]:
np.array(tensor, int).ndim
Out[36]:
In [38]:
np.array(tensor, int).size
Out[38]:
In [44]:
a = np.array([[1,2,3], [4.5, 5, 6]], dtype=int)
a.dtype
Out[44]:
In [46]:
np.array([[1,2,3], [4.5, "5", "6"]], dtype=np.float32)
Out[46]:
In [48]:
np.array([[1,2,3], [4.5, "5", "6"]], dtype=np.float32).nbytes
Out[48]:
In [51]:
np.array([[1,2,3], [4.5, "5", "6"]], dtype=np.int8).nbytes
Out[51]:
In [53]:
np.array([[1,2,3], [4.5, "5", "6"]], dtype=np.float64).nbytes
Out[53]:
728x90
'Numpy' 카테고리의 다른 글
[Numpy] Operation, Dot product, Broadcasting (0) | 2021.07.16 |
---|---|
[Numpy] Operation_function, Concatenate (0) | 2021.07.16 |
[Numpy] Arange, ones, zeros, empty, eye, identity, digonal, random (0) | 2021.07.16 |
[Numpy] Indexing, Slicing (0) | 2021.07.16 |
[Numpy] Reshape (0) | 2021.07.16 |