Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
NumPy Beginner's Guide
NumPy Beginner's Guide

NumPy Beginner's Guide: An action packed guide using real world examples of the easy to use, high performance, free open source NumPy mathematical library. , Second Edition

eBook
€19.99 €28.99
Paperback
€37.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Table of content icon View table of contents Preview book icon Preview Book

NumPy Beginner's Guide

Chapter 1. NumPy Quick Start

Let's get started. We will install NumPy and related software on different operating systems and have a look at some simple code that uses NumPy. The IPython interactive shell is introduced briefly. As mentioned in the Preface, SciPy is closely related to NumPy, so you will see the SciPy name appearing here and there. At the end of this chapter, you will find pointers on how to find additional information online if you get stuck or are uncertain about the best way to solve problems.

In this chapter, we shall:

  • Install Python, SciPy, Matplotlib, IPython, and NumPy on Windows, Linux, and Macintosh

  • Write simple NumPy code

  • Get to know IPython

  • Browse online documentation and resources

Python


NumPy is based on Python, so it is required to have Python installed. On some operating systems, Python is already installed. However, you need to check whether the Python version corresponds with the NumPy version you want to install. There are many implementations of Python, including commercial implementations and distribution. In this book we will focus on the standard CPython implementation, which is guaranteed to be compatible with NumPy.

Time for action – installing Python on different operating systems


NumPy has binary installers for Windows, various Linux distributions, and Mac OS X. There is also a source distribution, if you prefer that. You need to have Python 2.4.x or above installed on your system. We will go through the various steps required to install Python on the following operating systems:

  1. Debian and Ubuntu: Python might already be installed on Debian and Ubuntu but the development headers are usually not. On Debian and Ubuntu install python and python-dev with the following commands:

    sudo apt-get install python
    sudo apt-get install python-dev
    
  2. Windows: The Windows Python installer can be found at www.python.org/download. On this website, we can also find installers for Mac OS X and source tarballs for Linux, Unix, and Mac OS X.

  3. Mac: Python comes pre-installed on Mac OS X. We can also get Python through MacPorts, Fink, or similar projects. We can install, for instance, the Python 2.7 port by running the following command:

    sudo port install python27
    

    LAPACK does not need to be present but, if it is, NumPy will detect it and use it during the installation phase. It is recommended to install LAPACK for serious numerical analysis as it has useful numerical linear algebra functionality.

What just happened?

We installed Python on Debian, Ubuntu, Windows, and the Mac.

Windows


Installing NumPy on Windows is straightforward. You only need to download an installer, and a wizard will guide you through the installation steps.

Time for action – installing NumPy, Matplotlib, SciPy, and IPython on Windows


Installing NumPy on Windows is necessary but, fortunately, a straightforward task that we will cover in detail. It is recommended to install Matplotlib, SciPy, and IPython. However, this is not required to enjoy this book. The actions we will take are as follows:

  1. Download a NumPy installer for Windows from the SourceForge website http://sourceforge.net/projects/numpy/files/.

    Choose the appropriate version. In this example, we chose numpy-1.7.0-win32-superpack-python2.7.exe.

  2. Open the EXE installer by double clicking on it.

  3. Now, we can see a description of NumPy and its features as shown in the previous screenshot. Click on the Next button.

  4. If you have Python installed, it should automatically be detected. If it is not detected, maybe your path settings are wrong. At the end of this chapter, resources are listed in case you have problems installing NumPy.

  5. In this example, Python 2.7 was found. Click on the Next button if Python is found; otherwise, click on the Cancel button and install Python (NumPy cannot be installed without Python). Click on the Next button. This is the point of no return. Well, kind of, but it is best to make sure that you are installing to the proper directory and so on and so forth. Now the real installation starts. This may take a while.

  6. Install SciPy and Matplotlib with the Enthought distribution http://www.enthought.com/products/epd.php. It might be necessary to put the msvcp71.dll file in your C:\Windows\system32 directory. You can get it from http://www.dll-files.com/dllindex/dll-files.shtml?msvcp71. A Windows IPython installer is available on the IPython website (see http://ipython.scipy.org/Wiki/IpythonOnWindows).

What just happened?

We installed NumPy, SciPy, Matplotlib, and IPython on Windows.

Linux


Installing NumPy and related recommended software on Linux depends on the distribution you have. We will discuss how you would install NumPy from the command line, although, you could probably use graphical installers; it depends on your distribution (distro). The commands to install Matplotlib, SciPy, and IPython are the same – only the package names are different. Installing Matplotlib, SciPy, and IPython is recommended, but optional.

Time for action – installing NumPy, Matplotlib, SciPy, and IPython on Linux


Most Linux distributions have NumPy packages. We will go through the necessary steps for some of the popular Linux distros:

  1. Run the following instructions from the command line for installing NumPy and Red Hat:

    yum install python-numpy
    
  2. To install NumPy on Mandriva, run the following command-line instruction:

    urpmi python-numpy
    
  3. To install NumPy on Gentoo run the following command-line instruction:

    sudo emerge numpy
    
  4. To install NumPy on Debian or Ubuntu, we need to type the following :

    sudo apt-get install python-numpy
    

The following table gives an overview of the Linux distributions and corresponding package names for NumPy, SciPy, Matplotlib, and IPython.

Linux distribution

NumPy

SciPy

Matplotlib

IPython

Arch Linux

python-numpy

python-scipy

python-matplotlib

ipython

Debian

python-numpy

python-scipy

python-matplotlib

ipython

Fedora

numpy

python-scipy

python-matplotlib

ipython

Gentoo

dev-python/numpy

scipy

matplotlib

ipython

OpenSUSE

python-numpy, python-numpy-devel

python-scipy

python-matplotlib

ipython

Slackware

numpy

scipy

matplotlib

ipython

What just happened?

We installed NumPy, SciPy, Matplotlib, and IPython on various Linux distributions.

Mac OS X


You can install NumPy, Matplotlib, and SciPy on the Mac with a graphical installer or from the command line with a port manager such as MacPorts or Fink, depending on your preference.

Time for action – installing NumPy, Matplotlib, and SciPy on Mac OS X


We will install NumPy with a GUI installer using the following steps:

  1. We can get a NumPy installer from the SourceForge website http://sourceforge.net/projects/numpy/files/. Similar files exist for Matplotlib and SciPy. Just change numpy in the previous URL to scipy or matplotlib. IPython didn't have a GUI installer at the time of writing. Download the appropriate DMG file as shown in the following screenshot, usually the latest one is the best:

  2. Open the DMG file as shown in the following screenshot (in this example, numpy-1.7.0-py2.7-python.org-macosx10.6.dmg):

    • Double-click on the icon of the opened box, the one having a subscript that ends with .mpkg. We will be presented with the welcome screen of the installer.

    • Click on the Continue button to go to the Read Me screen, where we will be presented with a short description of NumPy as shown in the following screenshot:

    • Click on the Continue button to the License the screen.

  3. Read the license, click on the Continue button and then on the Accept button, when prompted to accept the license. Continue through the next screens and click on the Finish button at the end.

What just happened?

We installed NumPy on Mac OS X with a GUI installer. The steps to install SciPy and Matplotlib are similar and can be performed using the URLs mentioned in the first step.

Time for action – installing NumPy, SciPy, Matplotlib, and IPython with MacPorts or Fink


Alternatively, we can install NumPy, SciPy, Matplotlib, and IPython through the MacPorts route or with Fink. The following installation steps shown install all these packages. We only need NumPy for all the tutorials in this book, so please omit the packages you are not interested in.

  1. For installing with MacPorts, type the following command:

    sudo port install py-numpy py-scipy py-matplotlib py-ipython
    
  2. Fink also has packages for NumPy: scipy-core-py24, scipy-core-py25, and scipy-core-py26. The SciPy packages are: scipy-py24, scipy-py25, and scipy-py26. We can install NumPy and the other recommended packages we will be using in this book for Python 2.6 with the following command:

    fink install scipy-core-py26 scipy-py26 matplotlib-py26
    

What just happened?

We installed NumPy and other recommended software on Mac OS X with MacPorts and Fink.

Building from source


We can retrieve the source code for NumPy with git as follows:

git clone git://github.com/numpy/numpy.git numpy

Install /usr/local with the following command:

python setup.py build
sudo python setup.py install --prefix=/usr/local

To build, we need a C compiler such as GCC and the Python header files in the python-dev or python-devel package.

Arrays


After going through the installation of NumPy, it's time to have a look at NumPy arrays. NumPy arrays are more efficient than Python lists, when it comes to numerical operations. NumPy code requires less explicit loops than equivalent Python code.

Time for action – adding vectors


Imagine that we want to add two vectors called a and b. Vector is used here in the mathematical sense meaning a one-dimensional array. We will learn in Chapter 5, Working with Matrices and ufuncs, about specialized NumPy arrays which represent matrices. The vector a holds the squares of integers 0 to n, for instance, if n is equal to 3, then a is equal to 0, 1, or 4. The vector b holds the cubes of integers 0 to n, so if n is equal to 3, then the vector b is equal to 0, 1, or 8. How would you do that using plain Python? After we come up with a solution, we will compare it with the NumPy equivalent.

  1. The following function solves the vector addition problem using pure Python without NumPy:

    def pythonsum(n):
       a = range(n)
       b = range(n)
       c = []
    
       for i in range(len(a)):
           a[i] = i ** 2
           b[i] = i ** 3
           c.append(a[i] + b[i])
    
       return c
  2. The following is a function that achieves the same with NumPy:

    def numpysum(n):
      a = numpy.arange(n) ** 2
      b = numpy.arange(n) ** 3
      c = a + b
      return c

Notice that numpysum() does not need a for loop. Also, we used the arange function from NumPy that creates a NumPy array for us with integers 0 to n. The arange function was imported; that is why it is prefixed with numpy.

Now comes the fun part. Remember that it is mentioned in the Preface that NumPy is faster when it comes to array operations. How much faster is Numpy, though? The following program will show us by measuring the elapsed time in microseconds, for the numpysum and pythonsum functions. It also prints the last two elements of the vector sum. Let's check that we get the same answers by using Python and NumPy:

#!/usr/bin/env/python

import sys
from datetime import datetime
import numpy as np

"""
 Chapter 1 of NumPy Beginners Guide.
 This program demonstrates vector addition the Python way.
 Run from the command line as follows
     
  python vectorsum.py n
 
 where n is an integer that specifies the size of the vectors.

 The first vector to be added contains the squares of 0 up to n. 
 The second vector contains the cubes of 0 up to n.
 The program prints the last 2 elements of the sum and the elapsed time.
"""

def numpysum(n):
   a = np.arange(n) ** 2
   b = np.arange(n) ** 3
   c = a + b

   return c

def pythonsum(n):
   a = range(n)
   b = range(n)
   c = []

   for i in range(len(a)):
       a[i] = i ** 2
       b[i] = i ** 3
       c.append(a[i] + b[i])

   return c
   
size = int(sys.argv[1])

start = datetime.now()
c = pythonsum(size)
delta = datetime.now() - start
print "The last 2 elements of the sum", c[-2:]
print "PythonSum elapsed time in microseconds", delta.microseconds

start = datetime.now()
c = numpysum(size)
delta = datetime.now() - start
print "The last 2 elements of the sum", c[-2:]
print "NumPySum elapsed time in microseconds", delta.microseconds

The output of the program for 1000, 2000, and 3000 vector elements is as follows:

$ python vectorsum.py 1000
The last 2 elements of the sum [995007996, 998001000]
PythonSum elapsed time in microseconds 707
The last 2 elements of the sum [995007996 998001000]
NumPySum elapsed time in microseconds 171
$ python vectorsum.py 2000
The last 2 elements of the sum [7980015996, 7992002000]
PythonSum elapsed time in microseconds 1420
The last 2 elements of the sum [7980015996 7992002000]
NumPySum elapsed time in microseconds 168
$ python vectorsum.py 4000
The last 2 elements of the sum [63920031996, 63968004000]
PythonSum elapsed time in microseconds 2829
The last 2 elements of the sum [63920031996 63968004000]
NumPySum elapsed time in microseconds 274

Tip

You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

What just happened?

Clearly, NumPy is much faster than the equivalent normal Python code. One thing is certain; we get the same results whether we are using NumPy or not. However, the result that is printed differs in representation. Notice that the result from the numpysum function does not have any commas. How come? Obviously we are not dealing with a Python list but with a NumPy array. It was mentioned in the Preface that NumPy arrays are specialized data structures for numerical data. We will learn more about NumPy arrays in the next chapter.

Pop quiz Functioning of the arange function

Q1. What does arange(5) do?

  1. Creates a Python list of 5 elements with values 1 to 5.

  2. Creates a Python list of 5 elements with values 0 to 4.

  3. Creates a NumPy array with values 1 to 5.

  4. Creates a NumPy array with values 0 to 4.

  5. None of the above.

Have a go hero – continue the analysis

The program we used here to compare the speed of NumPy and regular Python is not very scientific. We should at least repeat each measurement a couple of times. It would be nice to be able to calculate some statistics such as average times, and so on. Also, you might want to show plots of the measurements to friends and colleagues.

Tip

Hints to help can be found in the online documentation and resources listed at the end of this chapter. NumPy has, by the way, statistical functions that can calculate averages for you. I recommend using Matplotlib to produce plots. Chapter 9, Plotting with Matplotlib, gives a quick overview of Matplotlib.

IPython—an interactive shell


Scientists and engineers are used to experimenting. IPython was created by scientists with experimentation in mind. The interactive environment that IPython provides is viewed by many as a direct answer to Matlab, Mathematica, and Maple. You can find more information, including installation instructions, at: http://ipython.org/.

IPython is free, open source, and available for Linux, Unix, Mac OS X, and Windows. The IPython authors only request that you cite IPython in scientific work where IPython was used. Here is the list of basic IPython features:

  • Tab completion

  • History mechanism

  • Inline editing

  • Ability to call external Python scripts with %run

  • Access to system commands

  • Pylab switch

  • Access to Python debugger and profiler

The Pylab switch imports all the Scipy, NumPy, and Matplotlib packages. Without this switch, we would have to import every package we need, ourselves.

All we need to do is enter the following instruction on the command line:

$ ipython --pylab
Python 2.7.2 (default, Jun 20 2012, 16:23:33) 
Type "copyright", "credits" or "license" for more information.

IPython 0.14.dev -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

Welcome to pylab, a matplotlib-based Python environment [backend: MacOSX].
For more information, type 'help(pylab)'.
In [1]: quit()

The quit() function or Ctrl + D quits the IPython shell. We might want to be able to go back to our experiments. In IPython, it is easy to save a session for later:

In [1]: %logstart
Activating auto-logging. Current session state plus future input saved.
Filename       : ipython_log.py
Mode           : rotate
Output logging : False
Raw input log  : False
Timestamping   : False
State          : active

Let's say we have the vector addition program that we made in the current directory. We can run the script as follows:

In [1]: ls
README        vectorsum.py
In [2]: %run -i vectorsum.py 1000

As you probably remember, 1000 specifies the number of elements in a vector. The -d switch of %run starts an ipdb debugger and on typing c, the script is started. n steps through the code. Typing quit at the ipdb prompt exits the debugger.

In [2]: %run -d vectorsum.py 1000
*** Blank or comment
*** Blank or comment
Breakpoint 1 at: /Users/…/vectorsum.py:3
><string>(1)<module>()
ipdb> c
> /Users/…/vectorsum.py(3)<module>()
      2
1---> 3 import sys
      4 from datetime import datetime
ipdb> n
>
/Users/…/vectorsum.py(4)<module>()
1     3 import sys
----> 4 from datetime import datetime
      5 import numpy
ipdb> n
> /Users/…/vectorsum.py(5)<module>()
      4 from datetime import datetime
----> 5 import numpy
      6 
ipdb> quit

We can also profile our script by passing the -p option to %run.

In [4]: %run -p vectorsum.py 1000
         1058 function calls (1054 primitive calls) in 0.002 CPU seconds
   Ordered by: internal time
ncallstottimepercallcumtimepercallfilename:lineno(function)
1 0.001    0.001   0.001    0.001 vectorsum.py:28(pythonsum)
1 0.001    0.001   0.002    0.002 {execfile}
1000 0.000    0.0000.0000.000 {method 'append' of 'list' objects}
1 0.000    0.000    0.002    0.002 vectorsum.py:3(<module>)
1 0.000    0.0000.0000.000 vectorsum.py:21(numpysum)
3    0.000    0.0000.0000.000 {range}
1    0.000    0.0000.0000.000 arrayprint.py:175(_array2string)
3/1    0.000    0.0000.0000.000 arrayprint.py:246(array2string)
2    0.000    0.0000.0000.000 {method 'reduce' of 'numpy.ufunc' objects}
4    0.000    0.0000.0000.000 {built-in method now}
2    0.000    0.0000.0000.000 arrayprint.py:486(_formatInteger)
2    0.000    0.0000.0000.000 {numpy.core.multiarray.arange}
1    0.000    0.0000.0000.000 arrayprint.py:320(_formatArray)
3/1    0.000    0.0000.0000.000 numeric.py:1390(array_str)
1    0.000    0.0000.0000.000 numeric.py:216(asarray)
2    0.000    0.0000.0000.000 arrayprint.py:312(_extendLine)
1    0.000    0.0000.0000.000 fromnumeric.py:1043(ravel)
2    0.000    0.0000.0000.000 arrayprint.py:208(<lambda>)
1    0.000    0.000    0.002    0.002<string>:1(<module>)
11    0.000    0.0000.0000.000 {len}
2    0.000    0.0000.0000.000 {isinstance}
1    0.000    0.0000.0000.000 {reduce}
1    0.000    0.0000.0000.000 {method 'ravel' of 'numpy.ndarray' objects}
4    0.000    0.0000.0000.000 {method 'rstrip' of 'str' objects}
3    0.000    0.0000.0000.000 {issubclass}
2    0.000    0.0000.0000.000 {method 'item' of 'numpy.ndarray' objects}
1    0.000    0.0000.0000.000 {max}
1    0.000    0.0000.0000.000 {method 'disable' of '_lsprof.Profiler' objects}

This gives us a bit more insight into the workings of our program. In addition, we can now identify performance bottlenecks. The %hist command shows the commands history.

In [2]: a=2+2
In [3]: a
Out[3]: 4
In [4]: %hist
1: _ip.magic("hist ")
2: a=2+2
3: a

I hope you agree that IPython is a really useful tool!

Online resources and help


When we are in IPython's pylab mode , we can open manual pages for NumPy functions with the help command. It is not necessary to know the name of a function. We can type a few characters and then let tab completion do its work. Let's, for instance, browse the available information for the arange function.

In [2]: help ar<Tab>
In [2]: help arange

Another option is to put a question mark behind the function name:

In [3]: arange?

The main documentation website for NumPy and SciPy is at http://docs.scipy.org/doc/. Through this webpage, we can browse the NumPy reference at http://docs.scipy.org/doc/numpy/reference/ and the user guide as well as several tutorials.

NumPy has a wiki with lots of documentation at http://docs.scipy.org/numpy/Front%20Page/.

The NumPy and SciPy forum can be found at http://ask.scipy.org/en.

The popular Stack Overflow software development forum has hundreds of questions tagged numpy. To view them, go to http://stackoverflow.com/questions/tagged/numpy.

If you are really stuck with a problem or you want to be kept informed of NumPy development, you can subscribe to the NumPy discussion mailing list. The e-mail address is . The number of e-mails per day is not too high and there is almost no spam to speak of. Most importantly, developers actively involved with NumPy also answer questions asked on the discussion group. The complete list can be found at http://www.scipy.org/Mailing_Lists.

For IRC users, there is an IRC channel on irc.freenode.net. The channel is called #scipy, but you can also ask NumPy questions since SciPy users also have knowledge of NumPy, as SciPy is based on NumPy. There are at least 50 members on the SciPy channel at all times.

Summary


In this chapter, we installed NumPy and other recommended software that we will be using in some tutorials. We got a vector addition program working and convinced ourselves that NumPy has superior performance. We were introduced to the IPython interactive shell. In addition, we explored the available NumPy documentation and online resources.

In the next chapter, we will take a look under the hood and explore some fundamental concepts including arrays and data types.

Left arrow icon Right arrow icon

Key benefits

  • Perform high performance calculations with clean and efficient NumPy code.
  • Analyze large data sets with statistical functions
  • Execute complex linear algebra and mathematical computations

Description

NumPy is an extension to, and the fundamental package for scientific computing with Python. In today's world of science and technology, it is all about speed and flexibility. When it comes to scientific computing, NumPy is on the top of the list. NumPy Beginner's Guide will teach you about NumPy, a leading scientific computing library. NumPy replaces a lot of the functionality of Matlab and Mathematica, but in contrast to those products, is free and open source. Write readable, efficient, and fast code, which is as close to the language of mathematics as is currently possible with the cutting edge open source NumPy software library. Learn all the ins and outs of NumPy that requires you to know basic Python only. Save thousands of dollars on expensive software, while keeping all the flexibility and power of your favourite programming language.You will learn about installing and using NumPy and related concepts. At the end of the book we will explore some related scientific computing projects. This book will give you a solid foundation in NumPy arrays and universal functions. Through examples, you will also learn about plotting with Matplotlib and the related SciPy project. NumPy Beginner's Guide will help you be productive with NumPy and have you writing clean and fast code in no time at all.

Who is this book for?

If you are a programmer, scientist, or engineer who has basic Python knowledge and would like to be able to do numerical computations with Python, this book is for you. No prior knowledge of NumPy is required.

What you will learn

  • Install NumPy
  • NumPy arrays
  • Universal functions
  • NumPy matrices
  • NumPy modules
  • Plot with Matplotlib
  • Test NumPy code
  • Relation to SciPy

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Apr 25, 2013
Length: 310 pages
Edition : 2nd
Language : English
ISBN-13 : 9781782166092
Category :
Languages :
Concepts :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want

Product Details

Publication date : Apr 25, 2013
Length: 310 pages
Edition : 2nd
Language : English
ISBN-13 : 9781782166092
Category :
Languages :
Concepts :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 117.97
NumPy Beginner's Guide
€37.99
Building Machine Learning Systems with Python
€41.99
NumPy Cookbook
€37.99
Total 117.97 Stars icon

Table of Contents

11 Chapters
NumPy Quick Start Chevron down icon Chevron up icon
Beginning with NumPy Fundamentals Chevron down icon Chevron up icon
Get in Terms with Commonly Used Functions Chevron down icon Chevron up icon
Convenience Functions for Your Convenience Chevron down icon Chevron up icon
Working with Matrices and ufuncs Chevron down icon Chevron up icon
Move Further with NumPy Modules Chevron down icon Chevron up icon
Peeking into Special Routines Chevron down icon Chevron up icon
Assure Quality with Testing Chevron down icon Chevron up icon
Plotting with Matplotlib Chevron down icon Chevron up icon
When NumPy is Not Enough – SciPy and Beyond Chevron down icon Chevron up icon
Playing with Pygame Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.2
(14 Ratings)
5 star 35.7%
4 star 50%
3 star 14.3%
2 star 0%
1 star 0%
Filter icon Filter
Top Reviews

Filter reviews by




nipun Jun 13, 2013
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I had written a review for this book on my blog here: http://nipunbatra.wordpress.com/2013/06/11/book-review-numpy-beginners-guide-second-edition/ I would recommend this book highly. It is very good for newcomers. For Python oldies it might be a little slow. NumPy Beginner's Guide - Second Edition
Amazon Verified review Amazon
Tamir Lousky Jun 15, 2013
Full star icon Full star icon Full star icon Full star icon Full star icon 5
The book is very well written, and tries (quite successfully) to address this specialized, complicated subject in a light, simplified manner without losing depth and oversimplifying. The book includes many down to earth examples and sample code, and many interesting exercises that help implement the material.It starts with a nice, gradual introduction to NumPy, its functions, data structures and uses (and of course, how to install it). Then, the book addresses how to handle, analyze and manipulate larger datasets with examples from stock market data. Around half way, the book focuses on matrices and linear systems. The last few subjects cover advanced topics which I didn't delve into yet.All in all, a very good book, fun to read and useful. Recommended to anyone interested in manipulating arrays, matrices and large datasets in python efficiently.For further information, please see the mini-review on my blog:http://bioblog3d.wordpress.com/2013/06/15/numpy-beginners-guide-review/
Amazon Verified review Amazon
ReaddyEddy Jul 03, 2013
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Who is it for:This is an excellent book for the Python programmer who wants to extend their knowledge into mathematical programming and those with a mathematical or engineering background who want to leverage open source alternatives to commercial tools by using the NumPy with Python.Installation and other packages:Installation on the main platforms and the relationship between NumPy and SciPy, and using the library with Matplotlib and other Python modules is well covered.What's covered:The coverage is goes from creating vectors and multi-dimensional matrices through calculating Eigenvectors, the FFT, complex numbers, polynomial fitting and many others.Example Code:The examples I've followed are well thought through and illustrate the use the relevant parts of the NumPy API required in a clear and concise manner. An increasing amount of mathematical background is needed and for a beginner the book should be read in conjunction with a text book covering the relevant material.Recommendation:I would heartily recommend the book both as tool for learning and as a working reference for the NumPy library and wish it had been available when I was going up the learning curve.
Amazon Verified review Amazon
Paul A. Courchene Jul 02, 2013
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I wish to comment on the excellent book by Ivan Idris. The text entitled NumPy Beginner's Guide, Second Edition is an outstanding book for a broad range of computer enthusiasts. While not all computer nerds are necessarily interested in Programming per se', in light of the growth and momentum of digital media, it is now a fact of life that many fields of employment require some basic introduction to computer programming. Whether you are a business or financial analyst, or perhaps a serious computer wanabee, or even a College student, it is now time to take the first step. With the momentum seen in the computer language of Python, many people who would otherwise not be inclined to learn this skill, never the less are posing some interest and saying "I wonder if I could do that?" This book will show you how. Since this book covers programming with Python from A to Z, and provides an easy path of self-learning, a number of people with a broad range of computer and math skills can accomplish these tasks.Yes, sitting in the classroom somewhere and listening to someone lecture on the fine points of computer programming may be the road to success for lots of people, but it is not beyond achieving this same goal of learning new skills by self-study ... In the first few pages of this book, the notion of interactive python is introduced (called IPython). That is, one would take a canned script or snippet of sample code and run it in a command line interpreter or interactive shell. That is a fancy name for entering code at a prompt, essentially using a cut and paste routine. How simple can it be ... Since the subject text has a bazillion examples or python routines and coding structure, one can view a broad range of examples from the simplistic to the quite advanced level. With this book, following along step by step or page by page, you can almost become a computer (read python) programmer, overnight. I. E., one enters the example code, then follows the book and reviews the resulting output, along with subtle hints about the interpreter operation. The shell (or debugger) will allow you to step into the code line by line and view the resultant computer operations. Thus, not only do you have visual feedback (to check your work) but one of the books highlights are the numerous "On-line resources and help" that will provide you with support material at a click of a mouse. As an aside, I regularly read the Yahoo email Group entitled "the Python Community"([...] each day where someone asks the basic question about "Where can I learn Python by way of self-study?" This book provides that answer and opportunity. So Chapter 1 of this book is appropriately entitled"NumPy Quick Start". As you begin Chapter 2, you will soon recognize the format that follows, and gives the reader (or student) an introduction to key Python topics. For example, to program a machine to organize and otherwise manipulate data, be it text or a set of integers, we need to know some basic objects such as data structures. So after a few words about a data structure like an "array", one needs to create an array using examples (code) from the book. With further comments about "What happened?", while creating an array, you will be provided a mini quiz or "Pop quiz" that will test your comprehension and understanding of the concept at hand. Obviously, the quiz is a good reinforcement tool to aid learning. Next, the author uses additional examples to lead you through some more variations of the objects that you are studying. That is: the "Time for Action" is now an opportunity to alter or create alternate arrays by manipulating their dimensions etc. This Time for Action is actually a number of requests (or examples) for "you to try it". Now, not only are you learning new skills and techniques but in fact are "gaining experience" with Python. As a computer wanabee, I now recommend that you take a pencil in hand and copy some of the examples on paper (that you may be interested in). This may be seen as a proactive learning experience and will help you understand some rudimentary things like the syntax (the ways words combine to form phrases or code) of the Python language.Let me clarify a point here, about this text. It is true that this text is focused on mathematical techniques that the average beginner may not be quite ready for, I. E. basic Statistics and Linear Models as seen in Chapter 3, but I would argue that as we discussed above, the layout of the book and its associated (read: excellent) format allows one to learn and gain experience, one step at a time. Chapter 4 of the book lays out additional functions that start to exhibit the power of NumPy. For example (page 95) starts a discussion of Polynomials, in layman's terms, that of finding a function the fits a set of data. I am of course assuming that you have some interest in math and "numbers" per se', if in fact you have searched for this book at Amazon.com Other Chapters go on to highlight such programming techniques as related to:(3). CSV files, Simple Statistics, Linear Models and Trend Lines, (4). Convenient Functions,(5). Matrices and Universal Functions, (6) Linear Algebra, Random Numbers, Distributions,(7). Special Routines for Sorting, Searching, Financial Functions. (8) Quality and Testing [of software],(9). Plotting (results such as Graphs, Histograms, Scatter Plots etc.),(10.) SciPy., a Python based system for Scientists, Engineering and Mathematics. and(11). PyGames. What could be more fun than learning to program games in Python. As you inspect this book, you will find something of interest to everyone who is acquainted with the word Python.It is an excellent book in a format that is easy to find a keyword or idea and will remain a valuable resource to you, for a long time.
Amazon Verified review Amazon
Roberto Avilés Jun 09, 2013
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I have been reviewing Ivan Idris Numpy `beginner's guide', second edition of a great book. While in the first edition he started explaining iPython and Matplotlib, this second is an even more practical guide: "less theory, more results". The first chapter deals with essentials as Python, iPython and libraries as NumPy, Matplotlib and Scipy and ends with applications to vectors and arrays using those tools. Just then in second chapter he goes deep into NumPy fundamentals with many exercises using arrays, including passing from an array to a list (exercise that helps to understand what are the differences and advantages of each data type.)Chapter 3 relates to common functions and applications to, example, finances and times. Chapter 4 deals with how to fit polynomials and also Smoothing and as an example, the Hanning function. Chapter 5 is related to matrices and "ufuncs" (short by universal functions) including how to create it and use with a code. These ideas are applied to a classic, Fibonacci numbers but also to Lissajous curves and the drawing of sawtooth and triangle waves, and also how to work with bitwise comparison operations. Up to this point this is the perfect companion for a crash course on the uses of Python and libraries like NumPy; however is also strong enough to be used as part of a college lecture or as the tool that should not be absent in your tool box and desk. Is hard to summarize further chapters; is a very good book because Idris shows his ability to explain in clear and concise sentences and then he applies immediately to exercises in a variety of areas. If you can't find what you need in this book, the only solution might be a do it yourself solution, based in the' big book', the web! In chapter 6 he explains applications to Linear Algebra including eigenvalues and eigenvectors, Fourier Transform, random numbers and applications to a gambling show. In chapter 7 he works with complex numbers, including sorting and searching, and even plays with Bessel functions. Chapter 8 deals on Assuring Quality with Testing and how to assert and compare arrays. Chapter 9 is one of my favorites, because Idris shows excellent examples on how to plot using Matplotlib, including animations! If you cannot impress your audience with these tools, likely they are dead. In Chapter 10 he goes deeper on libraries like Scipy (NumPy + SciPy are essentials on dealing with big arrays of data, like images) but this time Idris also give us hints in how to deal with audio processing. Finally in Chapter 11, he talks about PyGame along with Matplotlib, Numpy and applications to ... Artificial Intelligence, and simulations of life.Certainly one book can hardly cover ALL `what we need'. However, is up to us to get the most of a tool. If you work on Engineering or Science and are in need to deal with data, vectors, matrices, arrays, sounds or images, if you need to plot and to make things evident to others, if you need a data handling Swiss tool in your toolkit, this is it, clear, concise, full of many examples in so many areas that you will always have something to talk with others even from areas different to yours. Read it, use it, enjoy it.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.