Friday, 21 June 2013

NumPy learning notes

RPi started compiling OpenCV around 12 noon, and just now I checked that it is still working hard.  I take this opportunity to read the OpenCV config file.  I found a couple of names I never heard of, including NumPy and Sphinx.  I have the feeling that they should be useful.  I am wiking these names new to me.

Wiki gives me some good news.  

1. NumPy operations on arrays and matrices are almost as quickly as C.  

In other words, NumPy is lazy hobbists's C language.

2. NumPy is functionally equivalent to MathLab.  I have heard about MatLab many years ago, but have no chance to try it.  

Now there is free NumPy and SciPy, which I think can be seen as poorman's MatLab. 


NumPy - Wikipedia

Original author(s) Travis Oliphant

Developer(s) Community project

Initial release 1995

Stable release 1.7.0 / February 9, 2013; 4 months ago

Operating system Cross-platform

Type Technical computing

License BSD-new license

Website www.numpy.org


NumPy is an extension to the Python programming language, adding support for large, multi-dimensional arrays and matrices, along with a large library of high-level mathematical functions to operate on these arrays. 

The ancestor of NumPy, Numeric, was originally created by Jim Hugunin with contributions from several other developers. In 2005, Travis Oliphant created NumPy by incorporating features of Numarray into Numeric with extensive modifications. NumPy is open source and has many contributors.


Because Python is currently implemented as an interpreter, mathematical algorithms written in it often run slower than compiled equivalents. Numpy seeks to address this problem for numerical algorithms by providing multidimensional arrays and functions and operators that operate efficiently on arrays. Thus any algorithm that can be expressed primarily as operations on arrays and matrices can run almost as quickly as the equivalent C code.


Using NumPy in Python gives functionality comparable to MATLAB since they are both interpreted, and they both allow the user to write fast programs as long as most operations work on arrays or matrices instead of scalars. 

In comparison, MATLAB boasts a large number of additional toolboxes, notably Simulink; whereas NumPy is intrinsically integrated with Python, a more modern, complete, and open source programming language. Moreover complementary Python packages are available; SciPy is a library that adds more MATLAB-like functionality and Matplotlib is a plotting package that provides MATLAB-like plotting functionality. Internally, both MATLAB and NumPy rely on LAPACK for efficient linear algebra computations.

Example

The following is a simple example of how to do interactive array manipulations and plot a graph with NumPy and Matplotlib.

>>> import numpy
>>> from matplotlib import pyplot
>>> x = numpy.linspace(0, 2 * numpy.pi, 100)
>>> y = numpy.sin(x)
>>> pyplot.plot(x, y)
>>> pyplot.show()

History

NumPy is based on two earlier Python array packages. The original one, Numeric, which is reasonably complete and stable, remains available, but is now obsolete. It was originally written in 1995 largely by Jim Hugunin with the help of many people including Jim Fulton, David Ascher, Paul DuBois,[2] and Konrad Hinsen. A newer implementation, Numarray, is a complete rewrite of Numeric but is also deprecated.[3] NumPy is a merge between the two that builds on the code base of Numeric and adds the features of Numarray.

There was a desire to get Numeric into the Python standard library, but Guido van Rossum (the author of Python) was quite clear that the code was not maintainable in its state then. Another problem was that for large arrays Numeric is very slow. As a result, another package called Numarray was created. Numarray is faster for large arrays, but slower for small arrays. For a time both Numeric and Numarray were used, both with different ways to accomplish similar goals. The last version of Numeric v24.2 was released on 11 November 2005 and numarray v1.5.2 was released on 24 August 2006.[4]

In early 2005, Travis Oliphant wanted to unify the community around a single array package. The Numeric code was adapted to make it more maintainable and flexible enough to implement the novel features of Numarray. This new project was part of SciPy. To avoid installing a whole package just to get an array object, this new package was separated and called NumPy. While the source code is freely available and it contains significant documentation, there is also an extensive official Guide to NumPy.[5] The documentation is built around a unified docstring standard.[6]

The release version 1.5.1 of NumPy is compatible with Python versions 2.4–2.7 and 3.1–3.2. Support for Python 3 was added in 1.5.0.[7] In 2011, PyPy started development on an implementation of the numpy API for PyPy.[8]

Video sources

There are several videos recorded in the seminars and the conferences. These videos may help beginners learn how NumPy works. 2009 SciPy meeting had several sessions on SciPy and NumPy.[9]

.END

-- General configuration for opencv 2.3.1 =====================================
--
--     Built as dynamic libs?:     YES
--     Compiler:                   /usr/bin/c++
--     C++ flags (Release):          -Wall -pthread -ffunction-sections  -O3 -DNDEBUG  -fomit-frame-pointer -DNDEBUG
--     C++ flags (Debug):            -Wall -pthread -ffunction-sections  -g  -O0 -DDEBUG -D_DEBUG -ggdb3
--     Linker flags (Release):
--     Linker flags (Debug):
--
--   GUI:
--     GTK+ 2.x:                   YES
--     GThread:                    YES
--
--   Media I/O:
--     ZLib:                       YES
--     JPEG:                       TRUE
--     PNG:                        TRUE
--     TIFF:                       build
--     JPEG 2000:                  build
--     OpenEXR:                    NO
--     OpenNI:                     NO
--     OpenNI PrimeSensor Modules: NO
--     XIMEA:                      NO
--
--   Video I/O:
--     DC1394 1.x:                 NO
--     DC1394 2.x:                 YES
--     FFMPEG:                     NO
--       codec:                    YES
--       format:                   YES
--       util:                     YES
--       swscale:                  NO
--       gentoo-style:             YES
--     GStreamer:                  NO
--     UniCap:                     NO
--     PvAPI:                      NO
--     V4L/V4L2:                   Using libv4l
--     Xine:                       NO
--
--   Other third-party libraries:
--     Use IPP:                    NO
--     Use TBB:                    NO
--     Use ThreadingFramework:     NO
--     Use Cuda:                   NO
--     Use Eigen:                  NO
--
--   Interfaces:
--     Python:                     YES
--     Python interpreter:         /usr/bin/python -B (ver 2.7)
--     Python numpy:               YES
--     Java:                       NO
--
--   Documentation:
--     Sphinx:                     NO
--     PdfLaTeX compiler:          /usr/bin/pdflatex
--     Build Documentation:        NO
--
--   Tests and samples:
--     Tests:                      YES
--     Examples:                   YES
--
--   Install path:                 /usr/local
--
--   cvconfig.h is in:             /home/pi/fongvision/OpenCV-2.3.1/build
-- -----------------------------------------------------------------
--
-- Configuring done
-- Generating done

.END

No comments:

Post a Comment