주요 콘텐츠

MATLAB 데이터를 Python에 전달하기

MATLAB®에서 Python® 함수를 호출할 경우 MATLAB의 Python 인터페이스는 MATLAB 데이터를 Python 언어에서 가장 잘 나타낼 수 있는 유형으로 변환합니다. MATLAB에서의 Python 데이터 사용에 대한 자세한 내용은 Python 함수에서 반환된 데이터 처리하기 항목을 참조하십시오.

PythonMATLAB 스칼라 데이터 전달하기

MATLAB에서, 스칼라 데이터를 MATLAB에서 Python 함수로 전달할 경우 Python 인터페이스가 데이터를 그에 해당하는 Python 데이터형으로 변환합니다.

MATLAB 입력 인수 유형 —
스칼라 값만 해당

결과 Python py. 데이터형

예제

double(실수)
single(실수)

float(디폴트 값) 또는 int

MATLAB에서 Python 숫자형 변수 사용하기

기본적으로 Python 인터페이스는 double형 또는 single형을 Python float으로 변환합니다.
Python 유형 힌트에 기반한 정수 값의 경우 Python 인터페이스는 double형 또는 single형을 Python int로 변환할 수 있습니다.

double(복소수)
single(복소수)

complex

z = complex(1,2);
py.cmath.polar(z)
ans = 
  Python tuple with values:

    (2.23606797749979, 1.1071487177940904)

int8
uint8
int16
uint16
int32

int

-

uint32
int64
uint64

int

-

NaN

float("nan")

-

Inf

float("inf")

-

string형 스칼라
char형 벡터

str

MATLAB에서 Python str 변수 사용하기

string형의 <missing>

None

py.list({string(missing),"Value"})
ans = 
  Python list with values:

    [None, 'Value']

logical

bool

-

dictionary

dict

MATLAB에서 Python 딕셔너리 사용하기

struct

dict

MATLAB에서 Python 딕셔너리 사용하기
tablepy.pandas.DataFrameUse Python Pandas DataFrames in MATLAB
timetablepy.pandas.DataFrameUse Python Pandas DataFrames in MATLAB
datetime

py.datetime.datetime

Python에서 MATLAB datetime형 사용하기
duration

py.datetime.timedelta

Use MATLAB Duration Types with Python

Python 객체 — py.type

type

-

Python 함수에 대한 함수 핸들 @py.module.function

module.function

Pass Python Function to Python map Function

PythonMATLAB 배열 데이터 전달하기

MATLAB에서, MATLAB 배열을 Python 함수에 대한 입력값으로 전달하고 Python 환경에서 NumPy 모듈이 사용 가능한 경우, Python 인터페이스는 배열을 Python NumPy 배열로 자동으로 변환합니다. MATLAB 배열을 Python 함수에 대한 입력값으로 전달할 때 NumPy 모듈을 사용할 수 없다면 Python 인터페이스는 행렬 입력값을 처리하는 방식으로 벡터 입력값도 처리합니다. Python 인터페이스는 이러한 입력값을 Python memoryview 객체로 변환합니다. (R2025a 이후)

R2025a 이전: NumPy 패키지를 사용하거나 사용하지 않고 MATLAB 벡터를 Python 함수에 전달하면 Python 인터페이스는 이 벡터를 Python array.array 객체로 변환합니다.

MATLAB 입력 배열 유형

NumPy를 사용했을 때의 Python 유형

double(실수)

numpy.array(dtype=np.float64)

single(실수)

numpy.array(dtype=np.float32)

int8(실수)

numpy.array(dtype=np.int8)

uint8(실수)

numpy.array(dtype=np.uint8)

int16(실수)

numpy.array(dtype=np.int16)

uint16(실수)

numpy.array(dtype=np.uint16)

int32(실수)

numpy.array(dtype=np.int32)

uint32(실수)

numpy.array(dtype=np.uint32)

int64(실수)

numpy.array(dtype=np.int64)

uint64(실수)

numpy.array(dtype=np.uint64)

double(복소수)

numpy.array(dtype=np.complex128)

single(복소수)

numpy.array(dtype=np.complex64)

logical

numpy.array(dtype=np.bool)

char형 벡터

str

cell형 벡터

tuple

datetime형 배열

numpy.datetime64 배열

duration형 배열

numpy.timedelta64 배열

char형 행렬
string형 배열

이 변환은 지원되지 않습니다.

Python 언어는 MATLAB 배열에 저장된 데이터 같은 메모리 버퍼에 액세스하기 위한 프로토콜을 제공합니다. NumPy가 설치되어 있지 않으면, Python 인터페이스는 데이터를 복사하지 않고 MATLAB과 동일한 프로세스에서 실행하여 MATLAB 배열을 Python 코드에서 바로 읽어 들일 수 있도록 MATLAB 배열에 대해 이 Python 버퍼 프로토콜을 구현합니다. 그런 다음 이 데이터 버퍼는 Python memoryview 객체로 변환됩니다. 다음 예시에서 Python 인터페이스는 MATLAB 배열 marrarray.array 생성자에 전달하면서 배열 marrmemoryview 객체로 변환합니다.

marr = [1,2,3];
pyarr = py.array.array('d',marr);

지원되지 않는 MATLAB 유형

다음 MATLAB 유형은 Python에서 지원되지 않습니다.

  • 다차원 char 배열 또는 cell 배열

  • 희소 배열

  • struct 배열

  • categorical

  • containers.Map

  • MATLAB 객체

  • matlab.metadata.Class (py.class)

참고 항목

도움말 항목