フィルターのクリア

Indexing custom Python objects

1 回表示 (過去 30 日間)
Gabor Bekes
Gabor Bekes 2019 年 9 月 2 日
コメント済み: Matthias Mayer 2020 年 9 月 17 日
Hello,
I want to be able to use indexable Python objects via MATLAB's Python interface. The context is, I need to process .odb files, created by the Abaqus FEM tool, which has a built in Python interpreter with the appropriate module to process such files, so the goal is to be able to handle this from MATLAB.
The problem is that MATLAB only sees a limited subset of attributes on these objects, for example it doesn't see the __getitem__ method that's needed to be able to index them. Ideally, I would do something along the lines of the following:
a = py.numpy.array([1, 2, 3]);
get = py.getattr(a, '__getitem__');
get(0)
Currently, the workaround is to use py.eval with a workspace dictionary, but I expect that being able to use indexing will be faster. I will happily provide further details if needed.
Thanks!
  1 件のコメント
Matthias Mayer
Matthias Mayer 2020 年 9 月 17 日
Try casting the index to int32, i.e. with get(int32(0))

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeCall Python from MATLAB についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by