import numpy as np


# array(...)

arr = np.array([1,2,3]) # 1 dimension array

arr = np.array([[1,2,3],[4,5,6]], np.int32) # 2 dimension array as type int32


# zeros((w, h, ...)) # empty array

arr2 = np.zeros((2,3), np.float32) # == [[0,0,0],[0,0,0]] as type float32


# arange(n)

arr3 = np.arange(10) # == [0,1,2,...9]


# reshape(w, h, ...)

arr3 = arr3.reshape(2,5) # == [[0,1,2,3,4],[5,6,7,8,9]]


---


# swapaxes()

arr.shape # (2, 3)

arr = arr.swapaxes(0, 1) # axe 0와 axe 1을 swap함

arr.shape # (3, 2) # shape을 통해 바뀐 axe 쉽게 확인가능


'Language > python' 카테고리의 다른 글

[python] logging example  (0) 2017.12.16
[python] unittest library - simple example  (0) 2017.12.15
[python] skimage ndarray shape (HWC, CHW)  (0) 2017.12.14
[python] ctypes API example  (0) 2017.12.13
[python] ctypes.memmove() example  (0) 2017.12.13

WRITTEN BY
hojongs
블로그 옮겼습니다 https://hojongs.github.io/