Can't pass cell array with shape of [N, 1] to matlab from Python
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 38/100
Direzione di ricerca
Start with the Python MWE using start_instance, loadcase, workspace, and the MATLAB engine, then compare the native and round-trip bus_name sizes. Done means a nested [N, 1] cell array remains [N, 1] when passed from Python back to MATLAB and the runpf round trip succeeds.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Nested list of shape [N, 1] is passed as [1, 1], causing error array cell dimension. From matlab, cell array [N,1] is passed to Python as list [N], but send it back will make it into [1, N]. Nested [N, 1] from Python will be treated as [1, 1]
Python MWE:
from matpower import start_instance
m = start_instance(engine="matlab")
CASE_NAME = "case_RTS_GMLC.m"
m.eval(f"mpc_native = loadcase('{CASE_NAME}');", nargout=0)
print("MATLAB native class:", m.eval("class(mpc_native.bus_name)", nargout=1))
print("MATLAB native size :", m.eval("size(mpc_native.bus_name)", nargout=1))
mpc = m.loadcase(CASE_NAME)
bus_name = mpc["bus_name"]
print("Python type :", type(bus_name))
print("First entry :", bus_name[0])
print("First entry type :", type(bus_name[0]))
mpc["bus_name"] = np.atleast_2d(mpc["bus_name"]).tolist()
m.workspace["mpc_rt"] = mpc
print("Round-trip class :", m.eval("class(mpc_rt.bus_name)", nargout=1))
print("Round-trip size :", m.eval("size(mpc_rt.bus_name)", nargout=1))
m.eval("runpf(mpc_native);", nargout=0) # success due to correct cell shape
m.eval("runpf(mpc_rt);", nargout=0) # fail due to [[1.0,1.0]] array for bus_name
m.exit()
MATLAB native class: cell
MATLAB native size : [[73.0,1.0]]
Python type : <class 'list'>
First entry : ABEL
First entry type : <class 'str'>
Round-trip class : cell
Round-trip size : [[1.0,1.0]]
- Lingua principale
- Python
- Stelle
- 97
- Fork
- 13
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di mathworks/matlab-engine-for-python
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 78/100
-
Support sparse array Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 42/100
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
-
Failed to build matlabengine Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
Tutte le issue di mathworks/matlab-engine-for-python
Issue simili
-
documentation help wanted
Difficoltà 2/5 1-3 ore Idoneità per principianti 90/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 90/100
simonw/sqlite-utils#872 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100