Main Content

이 번역 페이지는 최신 내용을 담고 있지 않습니다. 최신 내용을 영문으로 보려면 여기를 클릭하십시오.

Python 함수에서 반환된 데이터 처리하기

Python 유형을 MATLAB 유형으로 자동 변환하기

MATLAB®은 Python® 함수에서 반환된 다음 데이터형을 MATLAB 유형으로 자동 변환합니다. 다른 유형을 변환하려면 Python 유형을 MATLAB 유형으로 명시적으로 변환하기 항목을 참조하십시오.

Python에 표시되는 Python 반환 데이터형

결과 MATLAB 유형 — 스칼라

float

double

complex

복소수 double

bool

logical

datetime

datetime

Python 유형을 MATLAB 유형으로 명시적으로 변환하기

Python 함수의 출력값이 숫자형 또는 논리형이고 numpy.ndarray와 같은 Python 버퍼 프로토콜을 구현하는 경우, MATLAB에 다음 항목이 표시됩니다.

  • 실제 Python 유형

  • 기본 데이터

  • 해당하는 MATLAB 변환 함수. 이 함수를 사용하여 Python 객체를 MATLAB 배열로 완전히 변환할 수 있습니다.

다음 MATLAB 함수를 사용하여 Python 데이터형을 MATLAB 유형으로 변환합니다.

MATLAB에 표시되는 Python 반환 데이터형 또는 프로토콜

MATLAB 변환 함수

py.str

string
char

MATLAB에서 Python str 변수 사용하기

__str__ 메서드가 있는 객체

char

py.help('datetime.date.__str__')
Help on wrapper_descriptor in datetime.date:

datetime.date.__str__ = __str__(self, /)
    Return str(self).
d = py.datetime.date(...
    int32(2020),int32(3),int32(4));
char(d)
ans = '2020-3-04'

py.int
py.long
py.float
py.bool

숫자형 함수:
double
single
int8
uint8
int16
uint16
int32
uint32
int64
uint64

 
logical

py.bytes

uint8

 

py.array.array
py.numpy.ndarray
py.memoryview

모든 형식의 py.array.arraypy.memoryview 객체를 원하는 MATLAB 유형으로 변환할 수 있습니다.

숫자형 함수:
double
single
int8
uint8
int16
uint16
int32
uint32
int64
uint64

MATLAB에서 Python 숫자형 변수 사용하기 항목의 예제인 "MATLAB에서 Python 정수 array 유형 사용하기"

py.listpy.tuple

double
single
int8
uint8
int16
uint16
int32
uint32
int64
uint64
logical
string
cell

MATLAB에서 Python list 변수 사용하기
MATLAB에서 Python tuple 변수 사용하기

자세한 내용은 Error Converting Elements of list or tuple 항목을 참조하십시오.

매핑 프로토콜(예: py.dict)

struct

MATLAB에서 Python dict 변수 사용하기

py.datetime.datetime

datetime

dt = py.numpy.arange('2022-12-30', ...
    '2023-01-10',dtype='datetime64[D]');

py.datetime.timedelta

duration

td = py.numpy.array([1,2,3,4], ...
    dtype='timedelta64[h]');

예를 들어, Python 함수는 다음 배열 p를 반환합니다.

p = 

  Python ndarray:

     8     1     6
     3     5     7
     4     9     2

    Use details function to view the properties of the Python object.

    Use double function to convert to a MATLAB array.

다음을 입력하여 이 배열을 MATLAB 행렬 P로 변환할 수 있습니다.

P = double(p)
P = 3×3    
     8     1     6
     3     5     7
     4     9     2

p의 Python 속성에 대한 구체적인 정보가 필요하면 다음과 같이 입력하십시오.

details(p)
    py.numpy.ndarray handle with properties:

           T: [1×1 py.numpy.ndarray]
        base: [1×1 py.NoneType]
      ctypes: [1×1 py.numpy.core._internal._ctypes]
        data: [1×3 py.memoryview]
       dtype: [1×1 py.numpy.dtype[float64]]
       flags: [1×1 py.numpy.flagsobj]
        flat: [1×1 py.numpy.flatiter]
        imag: [1×1 py.numpy.ndarray]
    itemsize: [1×1 py.int]
      nbytes: [1×1 py.int]
        ndim: [1×1 py.int]
        real: [1×1 py.numpy.ndarray]
       shape: [1×2 py.tuple]
        size: [1×1 py.int]
     strides: [1×2 py.tuple]

  Methods, Events, Superclasses

Python 모듈이 __doc__ 특성의 콘텐츠를 제공하는 경우, MATLAB은 이 정보로 연결됩니다.

관련 예제

세부 정보