Skip to main content

Posts

Showing posts from 2016

Make Your Own GUI with Python

Suppose you have written a Python script that carries out a simulation based on a physical model and creates a nice plot of the results. Now you wish to explore the model and run the calculation on many different sets of input parameters. What is the best way to proceed? You could write a script that runs the same calculation on a list of inputs that you select ahead of time: inputs = [(x0, y0, z0), (x1, y1, z1), (x2, y2, z2)] for I in inputs: # Insert simulation code here. You could place your script inside a function and call the function repeatedly from the IPython command line with different inputs: def run_simulation(x, y, z): # Insert simulation code here. Both methods work, but neither is ideal. If you use a script with an input list, you have to select the inputs ahead of time. If you find an interesting region of parameter space, you have to modify the script and run it again. If you embed your simulation within a function, you have to do a lot of typing at

Jupyter Notebooks

Happy New Year! Let’s start off 2016 by learning something new: Jupyter Notebooks , formerly known as IPython Notebooks. A Jupyter notebook is an interactive document that incorporates text, math, graphics, and code. It can be viewed in a Web browser. Unlike most documents, however, you can modify and execute the code inside the document. In this sense, a Jupyter notebook is similar to a session in Mathematica or Maple. The difference is that the interpreter running behind the scenes is not Mathematica or Maple. Jupyter notebooks were designed to run Ju lia, Pyt hon, and R , but they support over 40 languages at present. The best way to learn about Jupyter notebooks is to take a look at one. This notebook is a simple example from a greenhorn, but you can find many more on the Web. Introduction.ipynb Click on the link to view the notebook. You can download the notebook using the Save icon at the upper right corner of the notebook Web page. You can then open th