For 2023 - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.
Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!
I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
What are numpy and scipy?
In Python, all
the operators are really methods - in other words, you write
c = d + e
and you're really writing
c = d . __add__ ( e )
So this means that it's possible to use the language to handle data of any sort, including data types that aren't supported at standard. It's even possible to wrap up low level system types into the langauge, and control 16 bit integers, 32 bit integers, 64 bit integers, 32 bit floats, 64 bit floats and so on through the scripting language.
But Python goes further - even collection references such as
c = jp
use built in methods and you're really writing
This week, I've presented both a beginner and an intermediate private Python course, and at the start of the beginner course these features were quietly and intentionally overlooked - they're not "first day" stuff for newcomers and indeed they're not even last day stuff many time. But it turns out that - in the right circumstance - they can be very useful indeed ...
Scenario ... You are doing a lot of statistical work and data analysis, on sets of information which are huge. For the sake of efficiency, you've previously had to code in C, where you can choose the data type that's required (but minimalist) for your needs, and you can use arrays that work with sequential memory locations and so lookups are fast, rather than having to trapse through the lookup system of a list / hash type collection with its wonderful (and unneeded in your case) flexibility at the cost of speed
Well - in this scenario, your C coding's going to be a bit slow; C isn't the fastest language to write
even though it can be fast to run
, and you find yourself taking a frustrating amount of research and development time up as you tweak and tune your code to experiment with the data that you're analysing, after all for experimental purposes.
Use Python as your controller, via the OO based interface I desrcide at the top, sweetened by the icing of the operators that Python provides. And use a well-tuned C library, with support for the low level data types (dtypes) that you need, and true arrays as a type too, to provide the fast power that's under the instruction of the scripted controller.
"Surely someone has done this before" you should be asking. and "surely it's available for me to download". Of course, you're right - you're looking at numpy
- numerical Python. You can see the source code of "Hello numpy world" ... [here]
Numpy goes further, though - once you've been provided with the interface to the basic types and true arrays, it became natural to add to the module to provide facilities which wouldn't be so natural on the more general types supported by the language; you'll see in the source code example:
print table + 5
which adds five to each member of a numpy array before printing it out - array aithmetic. And it's natural to support array addition and array multiplication too (yes, it does).
There's another requirement too - you'll often want to initialise a whole array, perhaps multidimensional, to a mathematical sequence of some sort. Perhaps that would be to a simple series of numbers (an array range or arange
), or perhaps to something more complex. And, yes, numpy provides such things:
tab2 = numpy.indices((3,3))
in my little example linked abve. There are further examples [here]
Numpy is only used by a small proportion of Python users - but for that small proportion it's vital stuff. We don't do more than mention it on our regular public courses, but I can provide you with a couple of hours insight on private sessions. If you're a mathematician, you'll soon get to know far more of the detail than I do - and that's doubly so if you add on the extra scipy
module which adds a whole raft of different statistical and mathematical algorithms - all ready-coded for you, operating on the C based structures for C execution speed, but controlled by the Python script for Python coding efficiency. (written 2010-10-09)
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articlesY118 - Python - numpy, scipy and matplotlib 
Loading and saving data - Python / numpy - (2010-10-09) 
Matplotlib - graphing in Python - teaching examples - (2010-10-10) 
Arrays v Lists - what is the difference, why use one or the other - (2010-10-10) 
3D graphics - web site usage - simple matplotlib and python example - (2010-10-12) 
Learning more about our web site - and learning how to learn about yours - (2011-12-17) 
A first graph with Matplotlib in Python - (2015-02-22) 
Graphing presentations in Python - huge data, numpy and matplotlib - (2015-02-28)
Some other Articles
Python - some common questions answered in code examplesWhat are numpy and scipy?Oddballs in PlymouthNot mugged in London!Memorial to a day in 1999Python dictionaries - reaching to new usesRight place, right season
4759 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96 at 50 posts per page
This is a page archived from The Horse's Mouth at
the diary and writings of Graham Ellis.
Every attempt was made to provide current information at the time the
page was written, but things do move forward in our business - new software
releases, price changes, new techniques. Please check back via
our main site for current courses,
prices, versions, etc - any mention of a price in "The Horse's Mouth"
cannot be taken as an offer to supply at that price.
Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).