Scientific Analysis in Python. Python based scientific analysis cookbook James Battat Created: October 3, 2006 Last Modified: July 12, 2010 I find Python very user-friendly. Therefore I often reach for it when tasked to solve small or large scripting problems. I have been rather frustrated, though, with the level of support for scientific analysis packages. With scipy and matplotlib, of course, the tools are all there and success is just around the corner... But if you're like me and you're at a loss when trying to do something in Python because you're used to using other languages (IDL) for scientific analysis then you may find this page useful. Load scipy and matplotlib (all future code assumes that you have taken this step) import scipy import pylab Get help on a scipy or matplotlib routine help(pylab.hist) Make a scipy array from scratch array = scipy.c_[1, 2, 3, 4] print array # [1 2 3 4] # OR array = scipy.array([1,2,3,4]) print array [1 2 3 4] Next header.
NumPy for MATLAB users – Mathesaurus. Linear regression with pylab. In order to compliment my linear regression in google docs post (and because I keep forgetting how to do it), here is a quick and dirty guide to linear regression using python and pylab.
First some notes. One, there is some good info on this online (how else do you think I find this stuff?). Here is a great link: SciPy Cookbook on linear regression. Second, remember that I do things the ‘hard way’ sometimes. On to the problem. How about a plot? This is the graph it produces: Now to add a linear function to that data. Let me point out a couple of the key lines. (m,b) = polyfit(x,y,1) This calls the polyfit function (that is in the pylab module). Once I have the coefficients m and b, really I am finished. Yp = polyval([m,b],x) This just evaluates the polynomial with the coefficients [m,b] and value x.
To plot this, I want the fitting function as a normal line and the original data as just data points. This has a slope of 1.076 and an intercept of 2.771. And there you have it. Python/Unix Course. Peter Shearer (x42260, firstname.lastname@example.org) Website for class at We meet MWF from 10 to 10:50 in the IGPP Munk Lab Conference Room.
There will be no final. Grades will be based on homework. To participate, you should install on a Mac:gfortran (64-bit version) (also see NetOps wiki) XCode: Macs Developer's environment. Click on the "Mac Dev Center". Macs are recommended. Homework (all are due at midnight on last day) UNIX (due Wed. Check out these keys to optimal tic-tac-toe strategy going first and going second. Notes and other material Class notes (PDF) Simplicity, Flexibility, Beauty!, Kiwi PyCon 2011, August 27-28, 2011, Wellington, New Zealand.
Python for Scientists. In reaction to several colleagues asking about Python , I thought a webpage would be more useful than giving an exhaustive rundown on Python verbally. Python is a script based language that allows programmers/scientists to get their algorithms and functions working in little or no time. A large number of modules and wrappers are being built for Python, like RPy and Scipy , to allow advanced tools and faster processing speeds to be implemented. Plotting modules and programs are also in wide use among Python users. The wide array of tools that can be used for plotting provides great flexibility. To help users at all levels of Python familiarity, a list of handy links is given below in sections. Getting to Know Python If you're not too familiar with Python, the links below will help you learn the Python language. How to Think Like a Computer Scientist Detailed tutorial on Python Instant Python Installers for Extras Fink MacPorts Easy Install Enstaller Programming Environments IPython.