I’ve unpacked some values from a Python tuple like this:
14 ?- py_call($Ss:next_step(),_Obs,[py_object]), _Obs =.. [-,T,Pos,Occ,Cov,Cts].
T = 789.0,
Pos = <py_ndarray>(0000018ff1d0f9f0),
Occ = <py_ndarray>(0000018ff1c86910),
Cov = <py_list>(0000018ff2e062c0),
Cts = <py_ndarray>(0000018ff3c47090),
Ss = <py_SurveySimulationGrid>(0000018fc8f17d60).
Pos is a 2d array of zeroes with a single 1 and I want to get the coordinates of the 1. I’m trying to do this with numpy where()
but:
17 ?- py_call($Ss:next_step(),_Obs,[py_object]), _Obs =.. [-,T,Pos,Occ,Cov,Cts], py_call(numpy:where(Pos == 1),XY).
ERROR: Domain error: `py_term' expected, found `<py_ndarray>(0000018ff2dfcb10)==1'
ERROR: In:
ERROR: [13] janus:py_call(numpy:where(...),_5007164)
ERROR: [11] toplevel_call(user:user: ...) at c:/program files/swipl/boot/toplevel.pl:1318
ERROR:
ERROR: Note: some frames are missing due to last-call optimization.
ERROR: Re-run your program in debug mode (:- debug.) to get more detail.
^ Exception: (4) setup_call_cleanup('$toplevel':notrace(call_repl_loop_hook(begin, 0)), '$toplevel':'$query_loop'(0), '$toplevel':notrace(call_repl_loop_hook(end, 0))) ? abort
% Execution Aborted
More generally I have no idea how to access the elements of tuples and arrays positionally, in Janus. For example that’s why I’m unpacking _Obs
above with univ (also because it has ‘-’ as a functor and I want to get to the tuple values).
Suppose I try to do it like this, as I would normally in Python:
17 ?- py_call($Ss:next_step(),_Obs,[py_object]), _Obs =.. [-,T,Pos,Occ,Cov,Cts], py_call(Pos[1][1],El)
.
ERROR: Syntax error: Operator expected
ERROR: py_call($Ss:next_step(),_Obs,[py_object]), _Obs =.. [-,T,Pos,Occ,Cov,Cts], py_call(Po
ERROR: ** here **
ERROR: s[1][1],El) .
That’s not allowed. But then how do I access a tuple or array elements by index?