mport numpy as np
a = np.arange(12).reshape(3,4)
a[:2,:]
==> array([[0, 1, 2, 3], [4, 5, 6, 7]])
a[:,:3]
==> array([[ 0, 1, 2], [ 4, 5, 6], [ 8, 9, 10]])
# 증가치를 적용하여 요소 가져오기
b = np.arange(12)
b[::2]
==>array([ 0, 2, 4, 6, 8, 10])
# 역순으로 가져오기
b[::-1]
==> array([11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0])
# 역순으로 -2 증가하면서 가져오기
b[::-2]
==> array([11, 9, 7, 5, 3, 1])
# 모든 차원에 ... , ::
c = np.arange(24).reshape(4,3,2)
c
==> array([[[ 0, 1], [ 2, 3], [ 4, 5]], [[ 6, 7], [ 8, 9], [10, 11]], [[12, 13], [14, 15], [16, 17]], [[18, 19], [20, 21], [22, 23]]])
c[2,...] # c[2,::] , c[2,:], c[2,:,:]
==> array([[12, 13], [14, 15], [16, 17]])
|