Python 関数から返されたデータの処理
Python 型から MATLAB 型への自動変換
MATLAB® は Python® 関数から返された以下のデータ型を自動的に MATLAB 型に変換します。
Python に表示される Python の戻り値の型 | 結果の MATLAB の型 — スカラー |
|---|---|
|
|
| 複素数の |
|
|
datetime |
|
また、Python string オブジェクトを含む Python ディクショナリまたは Python Pandas DataFrame が Python から MATLAB に返されると、Python string オブジェクトは MATLAB string に変換されます。
Python 型から MATLAB 型への明示的な変換
以下の MATLAB 関数を使用して、Python データ型を MATLAB 型に明示的に変換できます。
MATLAB に表示される Python の戻り値の型またはプロトコル | MATLAB の変換関数 | 例 |
|---|---|---|
|
| MATLAB での Python str 変数の使用 |
|
| 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' |
|
| |
logical | ||
|
| |
任意の形式の |
| MATLAB での Python 数値変数の使用 |
|
| MATLAB での Python list 変数の使用 |
マッピング プロトコルを実装する |
| MATLAB での Python ディクショナリの使用 |
py.pandas.DataFrame |
| MATLAB での Python pandas DataFrame の使用 |
|
| dt = py.numpy.arange('2022-12-30', ... '2023-01-10',dtype='datetime64[D]'); |
|
| td = py.numpy.array([1,2,3,4], ... dtype='timedelta64[h]'); |
Python 関数の出力の型が、numpy.ndarray などの Python バッファー プロトコルを実装する型である場合、MATLAB によって以下が表示されます。
実際の Python 型
基となるデータ
対応する MATLAB 変換関数。この関数を使用して、Python オブジェクトを MATLAB 配列に完全に変換します。
たとえば、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.推奨された変換関数を使用して、p を 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, SuperclassesPython モジュールが __doc__ 属性でコンテンツを提供する場合、MATLAB はその情報にリンクします。