python - Maple Help

convert/python

convert to Python expression

 Calling Sequence convert(expr, python)

Parameters

 expr - expression to convert

Description

 • The convert(expr, python) command accepts a Maple expression and return a result suitable to use as input for Python[EvalFunction].
 • In this conversion, numeric literals and strings are left as is, and container structures such as tables and Arrays are replaced with references to equivalent Python structures.
 • Conversion of the following types is supported:

Examples

The convert command leaves this list unchanged as it can already be used with EvalFunction.

 > $\mathrm{convert}\left(\left[1,5,7\right],\mathrm{python}\right)$
 $\left[{1}{,}{5}{,}{7}\right]$ (1)
 > $\mathrm{Python}:-\mathrm{EvalFunction}\left("len",\left[1,5,7\right]\right)$
 ${3}$ (2)

This Vector is converted to an equivalent ndarray.

 > $\mathrm{pv}≔\mathrm{convert}\left(⟨1,5,7⟩,\mathrm{python}\right)$
 ${\mathrm{pv}}{≔}{""}$ (3)
 > $\mathrm{type}\left(\mathrm{pv},\mathrm{python}\right)$
 ${\mathrm{true}}$ (4)

This table is converted to a Python dictionary.

 > $T≔\mathrm{table}\left(\left["dog"="canine","cat"="feline"\right]\right)$
 ${T}{≔}{table}{}\left(\left[{"dog"}{=}{"canine"}{,}{"cat"}{=}{"feline"}\right]\right)$ (5)
 > $\mathrm{pd}≔\mathrm{convert}\left(T,\mathrm{python}\right)$
 ${\mathrm{pd}}{≔}{""}$ (6)
 > $\mathrm{type}\left(\mathrm{pd},\mathrm{python}\right)$
 ${\mathrm{true}}$ (7)

Compatibility

 • The convert/python command was introduced in Maple 2020.