Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - 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[4] = jp[3]
use built in methods and you're really writing
  c.__setitem__(4,jp.__getitem__(3))
See [example]

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.

Solution ... 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 articles
Y118 - Python - numpy, scipy and matplotlib
  [2991] Loading and saving data - Python / numpy - (2010-10-09)
  [2992] Matplotlib - graphing in Python - teaching examples - (2010-10-10)
  [2993] Arrays v Lists - what is the difference, why use one or the other - (2010-10-10)
  [2997] 3D graphics - web site usage - simple matplotlib and python example - (2010-10-12)
  [3554] Learning more about our web site - and learning how to learn about yours - (2011-12-17)
  [4440] A first graph with Matplotlib in Python - (2015-02-22)
  [4445] Graphing presentations in Python - huge data, numpy and matplotlib - (2015-02-28)


Back to
Oddballs in Plymouth
Previous and next
or
Horse's mouth home
Forward to
Loading and saving data - Python / numpy
Some other Articles
Python - some common questions answered in code examples
What are numpy and scipy?
Oddballs in Plymouth
Not mugged in London!
Memorial to a day in 1999
Python dictionaries - reaching to new uses
Right 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 http://www.wellho.net/horse/ - 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).

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/mouth/2990_Wha ... cipy-.html • PAGE BUILT: Sun Oct 11 16:07:41 2020 • BUILD SYSTEM: JelliaJamb