import numpy as np

스칼라 - 0D(demension, 차원) 텐서

크기만 갖고 있는 값

 

ex ) 1, 2, 3, ... , n

scalar = 3
zero_d_tenser = np.array(scalar)

print('값 : ', zero_d_tenser)
print('축(axis)의 개수 (= 차원) : ', zero_d_tenser.ndim)
print('크기 : ', zero_d_tenser.shape)


벡터 - 1D 텐서

크기방향을 갖는 1차원 값

(열,)

 

ex ) [ 1, 2, 3, ... , n ]

vec = [3, 6, 9]
one_d_tenser = np.array(vec)

print('값 : ', one_d_tenser)
print('축(axis)의 개수 (= 차원) : ', one_d_tenser.ndim)
print('크기 : ', one_d_tenser.shape)

 

위에 선언한 one_d_tenser는 3차원 벡터이자 1차원 텐서이다.

 

n차원 벡터 : 벡터 안 원소의 개수 (벡터에서의 차원)

n차원 텐서 : 축의 개수 (텐서에서의 차원)


행렬 - 2D 텐서

을 갖는 2차원 값

(행, 열)

 

ex ) [ [1, 2] , [3, 4], ... [n, m] ]

metrix= [[3], [6], [9]]
two_d_tenser = np.array(metrix)

print('값 : \n', two_d_tenser)
print('축(axis)의 개수 (= 차원) : ',two_d_tenser.ndim)
print('크기 : ', two_d_tenser.shape)

※ 주의 ※     이전글 참고 : 넘파이 배열(np.array)

metrix= [[3], [6, 7], [9]]
two_d_tenser = np.array(metrix)

print('값 : \n', two_d_tenser)
print('축(axis)의 개수 (= 차원) : ',two_d_tenser.ndim)
print('크기 : ', two_d_tenser.shape)


텐서 - 3D 텐서

, 깊이를 갖는 3차원 값

(깊이, 행, 열)

 

ex ) [ [[1, 2]], [[3, 4]], ... , [[n,m] ]

tensor= [[[1, 2, 3]], [[3, 4, 5]]]
three_d_tenser = np.array(tensor)

print('값 : \n', three_d_tenser)
print('축(axis)의 개수 (= 차원) : ',three_d_tenser.ndim)
print('크기 : ', three_d_tenser.shape)

tensor= [[[1, 2, 3], [3, 4, 5]], [[6, 7, 8], [9, 10, 11]]]
three_d_tenser = np.array(tensor)

print('값 : \n', three_d_tenser)
print('축(axis)의 개수 (= 차원) : ',three_d_tenser.ndim)
print('크기 : ', three_d_tenser.shape)

 

'ML > Numpy' 카테고리의 다른 글

[Numpy] argsort() 사용법  (0) 2023.01.10
[Numpy, Scipy] np.array, toarray() 차이  (0) 2022.12.16
[Numpy] 넘파이 배열(np.array)  (0) 2022.11.09