@@ -19,13 +19,13 @@ modifications by David Zwicker
1919
2020BeginPackage ["ToPython`" ]
2121
22- ToPython ::usage = "ToPython[expression, numpyprefix, copy ]
22+ ToPython ::usage = "ToPython[expression, NumpyPrefix-> \" np \" , Copy->False ]
2323 converts Mathematica expression to a Numpy compatible expression. Because Numpy can
24- be imported in several ways, numpyprefix is a string that will be added to appended
25- to function names, e.g., Cos->np.cos. If copy==True, the result is copied to the clipboard"
24+ be imported in several ways, you can specify the name of the numpy module using the
25+ NumpyPrefix option. The additional option Copy allows you to copy the result to the clipboard"
2626
27- ToPythonEquation ::usage = "ToPythonEquation[equation, numpyprefix, copy] converts a
28- Mathematica equation to a Numpy compatible express "
27+ ToPythonEquation ::usage = "ToPythonEquation[equation, NumpyPrefix-> \" np \" , Copy->False]
28+ converts a Mathematica equation to a Numpy compatible expression. "
2929
3030
3131
@@ -36,8 +36,10 @@ Begin["Private`"]
3636singleFunctions = {Log , Sin , Cos , Tan , Sinh , Cosh , Tanh };
3737
3838
39- ToPython [expression_ , numpyprefix_ :"np" , copy_ :False ] := Module [
40- {result , greekrule , format , PythonForm , np , br , brackets , a , b , l , m , args },
39+ Options [ToPython ] = {NumpyPrefix -> "np" , Copy -> False };
40+ ToPython [expression_ , OptionsPattern []] := Module [
41+ {numpyprefix = OptionValue [NumpyPrefix ], copy = OptionValue [Copy ],
42+ result , greekrule , format , PythonForm , np , br , brackets , a , b , l , m , args },
4143
4244(* determine the correct numpy prefix *)
4345If [numpyprefix == "" , np = numpyprefix , np = numpyprefix <> "." ];
@@ -128,7 +130,8 @@ result
128130]
129131
130132
131- ToPythonEquation [Equal [a_ , b_ ], numpyprefix_ :"np" , copy_ :True ] := ToPython [a - b , numpyprefix , copy ]
133+ Options [ToPythonEquation ] = {NumpyPrefix -> "np" , Copy -> False };
134+ ToPythonEquation [Equal [a_ , b_ ], opts : OptionsPattern []] := ToPython [a - b , opts ]
132135
133136
134137End []
0 commit comments