100% found this document useful (8 votes)
72 views

NumPy Beginner S Guide Third Edition Ivan Idris Download PDF

s

Uploaded by

alalimberila
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (8 votes)
72 views

NumPy Beginner S Guide Third Edition Ivan Idris Download PDF

s

Uploaded by

alalimberila
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 70

Get ebook downloads in full at ebookname.

com

NumPy Beginner s Guide Third Edition Ivan Idris

https://ebookname.com/product/numpy-beginner-s-guide-third-
edition-ivan-idris/

OR CLICK BUTTON

DOWNLOAD EBOOK

Explore and download more ebook at https://ebookname.com


Instant digital products (PDF, ePub, MOBI) available
Download now and explore formats that suit you...

NumPy Beginner s Guide 2nd Edition Ivan Idris

https://ebookname.com/product/numpy-beginner-s-guide-2nd-edition-
ivan-idris/

Absolute Beginner s Guide to Corel WordPerfect 10


Absolute Beginner s Guide 1st Edition Laura Acklen

https://ebookname.com/product/absolute-beginner-s-guide-to-corel-
wordperfect-10-absolute-beginner-s-guide-1st-edition-laura-
acklen/

Absolute Beginner s Guide to a Lite and Healthy


Lifestyle Absolute Beginner s Guide 1st Edition Nicole
Haywood

https://ebookname.com/product/absolute-beginner-s-guide-to-a-
lite-and-healthy-lifestyle-absolute-beginner-s-guide-1st-edition-
nicole-haywood/

The Development of International Human Rights Law


Volume I 1st Edition Fionnuala D. Ní Aoláin

https://ebookname.com/product/the-development-of-international-
human-rights-law-volume-i-1st-edition-fionnuala-d-ni-aolain/
Shorebird Ecology Conservation and Management 1st
Edition Dr. Mark A. Colwell

https://ebookname.com/product/shorebird-ecology-conservation-and-
management-1st-edition-dr-mark-a-colwell/

Netherlands Yearbook of International Law Volume 41


2010 Necessity Across International Law 1st Edition
Tarcisio Gazzini

https://ebookname.com/product/netherlands-yearbook-of-
international-law-volume-41-2010-necessity-across-international-
law-1st-edition-tarcisio-gazzini/

RESTful Web Services Cookbook Solutions for Improving


Scalability and Simplicity 1st Edition Subbu Allamaraju

https://ebookname.com/product/restful-web-services-cookbook-
solutions-for-improving-scalability-and-simplicity-1st-edition-
subbu-allamaraju/

Extreme Right Activists in Europe Through the


Magnifying Glass Routledge Studies in Extremism and
Democracy 1st Edition Pieter Klandermans

https://ebookname.com/product/extreme-right-activists-in-europe-
through-the-magnifying-glass-routledge-studies-in-extremism-and-
democracy-1st-edition-pieter-klandermans/

Being human in Islam The impact of the evolutionary


worldview 1st Edition Damian A. Howard

https://ebookname.com/product/being-human-in-islam-the-impact-of-
the-evolutionary-worldview-1st-edition-damian-a-howard/
Top 100 Health Care Careers 3rd Edition Dr. Saul
Wischnitzer & Edith Wischnitzer

https://ebookname.com/product/top-100-health-care-careers-3rd-
edition-dr-saul-wischnitzer-edith-wischnitzer/
NumPy Beginner's Guide
Third Edition

Build efficient, high-speed programs using the


high-performance NumPy mathematical library

Ivan Idris

BIRMINGHAM - MUMBAI
NumPy Beginner's Guide
Third Edition

Copyright © 2015 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system,
or transmitted in any form or by any means, without the prior written permission of the
publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the
information presented. However, the information contained in this book is sold without
warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers
and distributors will be held liable for any damages caused or alleged to be caused directly
or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the
companies and products mentioned in this book by the appropriate use of capitals.
However, Packt Publishing cannot guarantee the accuracy of this information.

First published: November 2011

Second edition: April 2013

Third edition: June 2015

Production reference: 1160615

Published by Packt Publishing Ltd.


Livery Place
35 Livery Street
Birmingham B3 2PB, UK.

ISBN 978-1-78528-196-9

www.packtpub.com
Credits

Author Project Coordinator


Ivan Idris Shweta H. Birwatkar

Reviewers Proofreader
Alexandre Devert Safis Editing
Davide Fiacconi
Ardo Illaste Indexer
Rekha Nair

Commissioning Editor
Amarabha Banerjee Graphics
Sheetal Aute

Acquisition Editors Jason Monteiro


Shaon Basu
Usha Iyer Production Coordinator
Aparna Bhagat
Rebecca Youe

Cover Work
Content Development Editor
Aparna Bhagat
Neeshma Ramakrishnan

Technical Editor
Rupali R. Shrawane

Copy Editors
Charlotte Carneiro
Vikrant Phadke
Sameen Siddiqui
About the Author

Ivan Idris has an MSc in experimental physics. His graduation thesis had a strong emphasis
on applied computer science. After graduating, he worked for several companies as a Java
developer, data warehouse developer, and QA Analyst. His main professional interests are
business intelligence, big data, and cloud computing. Ivan enjoys writing clean, testable
code and interesting technical articles. He is the author of NumPy Beginner's Guide, NumPy
Cookbook, Learning NumPy Array, and Python Data Analysis. You can find more information
about him and a blog with a few examples of NumPy at http://ivanidris.net/
wordpress/.

I would like to take this opportunity to thank the reviewers and the team
at Packt Publishing for making this book possible. Also thanks go to my
teachers, professors, colleagues, Wikipedia contributors, Stack Overflow
contributors, and other authors who taught me science and programming.
Last but not least, I would like to acknowledge my parents, family, and
friends for their support.
About the Reviewers

Davide Fiacconi is completing his PhD in theoretical astrophysics from the Institute for
Computational Science at the University of Zurich. He did his undergraduate and graduate
studies at the University of Milan-Bicocca, studying the evolution of collisional ring galaxies
using hydrodynamic numerical simulations. Davide's research now focuses on the formation
and coevolution of supermassive black holes and galaxies, using both massively parallel
simulations and analytical techniques. In particular, his interests include the formation of the
first supermassive black hole seeds, the dynamics of binary black holes, and the evolution of
high-redshift galaxies.

Ardo Illaste is a data scientist. He wants to provide everyone with easy access to data for
making major life and career decisions. He completed his PhD in computational biophysics,
prior to fully delving into data mining and machine learning. Ardo has worked and studied in
Estonia, the USA, and Switzerland.
www.PacktPub.com

Support files, eBooks, discount offers, and more


For support files and downloads related to your book, please visit www.PacktPub.com.

Did you know that Packt offers eBook versions of every book published, with PDF and ePub
files available? You can upgrade to the eBook version at www.PacktPub.com and as a print
book customer, you are entitled to a discount on the eBook copy. Get in touch with us at
service@packtpub.com for more details.

At www.PacktPub.com, you can also read a collection of free technical articles, sign up
for a range of free newsletters and receive exclusive discounts and offers on Packt books
and eBooks.
TM

https://www2.packtpub.com/books/subscription/packtlib

Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book
library. Here, you can search, access, and read Packt's entire library of books.

Why subscribe?
‹‹ Fully searchable across every book published by Packt
‹‹ Copy and paste, print, and bookmark content
‹‹ On demand and accessible via a web browser

Free access for Packt account holders


If you have an account with Packt at www.PacktPub.com, you can use this to access
PacktLib today and view 9 entirely free books. Simply use your login credentials for
immediate access.
I dedicate this book to my aunt Lies who recently passed away. Rest in peace.
Table of Contents
Preface ix
Chapter 1: NumPy Quick Start 1
Python 1
Time for action – installing Python on different operating systems 2
The Python help system 3
Time for action – using the Python help system 3
Basic arithmetic and variable assignment 4
Time for action – using Python as a calculator 4
Time for action – assigning values to variables 5
The print() function 6
Time for action – printing with the print() function 6
Code comments 7
Time for action – commenting code 7
The if statement 8
Time for action – deciding with the if statement 8
The for loop 9
Time for action – repeating instructions with loops 9
Python functions 11
Time for action – defining functions 11
Python modules 12
Time for action – importing modules 12
NumPy on Windows 13
Time for action – installing NumPy, matplotlib, SciPy, and IPython on Windows 13
NumPy on Linux 15
Time for action – installing NumPy, matplotlib, SciPy, and IPython on Linux 15
NumPy on Mac OS X 16
Time for action – installing NumPy, SciPy, matplotlib, and IPython with
MacPorts or Fink 16

[i]
Table of Contents

Building from source 16


Arrays 17
Time for action – adding vectors 17
IPython – an interactive shell 21
Online resources and help 25
Summary 26
Chapter 2: Beginning with NumPy Fundamentals 27
NumPy array object 28
Time for action – creating a multidimensional array 29
Selecting elements 30
NumPy numerical types 31
Data type objects 33
Character codes 33
The dtype constructors 34
The dtype attributes 35
Time for action – creating a record data type 35
One-dimensional slicing and indexing 36
Time for action – slicing and indexing multidimensional arrays 36
Time for action – manipulating array shapes 39
Time for action – stacking arrays 41
Time for action – splitting arrays 46
Time for action – converting arrays 51
Summary 51
Chapter 3: Getting Familiar with Commonly Used Functions 53
File I/O 53
Time for action – reading and writing files 54
Comma-seperated value files 55
Time for action – loading from CSV files 55
Volume Weighted Average Price 56
Time for action – calculating Volume Weighted Average Price 56
The mean() function 56
Time-weighted average price 57
Value range 58
Time for action – finding highest and lowest values 58
Statistics 59
Time for action – performing simple statistics 59
Stock returns 62
Time for action – analyzing stock returns 63
Dates 65

[ ii ]
Table of Contents

Time for action – dealing with dates 65


Time for action – using the datetime64 data type 69
Weekly summary 70
Time for action – summarizing data 70
Average True Range 74
Time for action – calculating Average True Range 75
Simple Moving Average 77
Time for action – computing the Simple Moving Average 77
Exponential Moving Average 80
Time for action – calculating the Exponential Moving Average 80
Bollinger Bands 82
Time for action – enveloping with Bollinger Bands 83
Linear model 86
Time for action – predicting price with a linear model 86
Trend lines 89
Time for action – drawing trend lines 90
Methods of ndarray 94
Time for action – clipping and compressing arrays 94
Factorial 95
Time for action – calculating the factorial 95
Missing values and Jackknife resampling 96
Time for action – handling NaNs with the nanmean(), nanvar(),
and nanstd() functions 97
Summary 98
Chapter 4: Convenience Functions for Your Convenience 99
Correlation 100
Time for action – trading correlated pairs 100
Polynomials 104
Time for action – fitting to polynomials 105
On-balance volume 108
Time for action – balancing volume 109
Simulation 111
Time for action – avoiding loops with vectorize() 111
Smoothing 114
Time for action – smoothing with the hanning() function 114
Initialization 118
Time for action – creating value initialized arrays with the full() and
full_like() functions 119
Summary 120

[ iii ]
Table of Contents

Chapter 5: Working with Matrices and ufuncs 121


Matrices 122
Time for action – creating matrices 122
Creating a matrix from other matrices 123
Time for action – creating a matrix from other matrices 123
Universal functions 125
Time for action – creating universal functions 125
Universal function methods 126
Time for action – applying the ufunc methods to the add function 127
Arithmetic functions 129
Time for action – dividing arrays 129
Modulo operation 131
Time for action – computing the modulo 131
Fibonacci numbers 132
Time for action – computing Fibonacci numbers 133
Lissajous curves 134
Time for action – drawing Lissajous curves 135
Square waves 136
Time for action – drawing a square wave 137
Sawtooth and triangle waves 138
Time for action – drawing sawtooth and triangle waves 139
Bitwise and comparison functions 140
Time for action – twiddling bits 141
Fancy indexing 143
Time for action – fancy indexing in-place for ufuncs with the at() method 144
Summary 144
Chapter 6: Moving Further with NumPy Modules 145
Linear algebra 145
Time for action – inverting matrices 146
Solving linear systems 148
Time for action – solving a linear system 148
Finding eigenvalues and eigenvectors 149
Time for action – determining eigenvalues and eigenvectors 150
Singular value decomposition 151
Time for action – decomposing a matrix 152
Pseudo inverse 154
Time for action – computing the pseudo inverse of a matrix 154
Determinants 155
Time for action – calculating the determinant of a matrix 155
Fast Fourier transform 156

[ iv ]
Table of Contents

Time for action – calculating the Fourier transform 156


Shifting 158
Time for action – shifting frequencies 158
Random numbers 160
Time for action – gambling with the binomial 161
Hypergeometric distribution 163
Time for action – simulating a game show 163
Continuous distributions 165
Time for action – drawing a normal distribution 165
Lognormal distribution 167
Time for action – drawing the lognormal distribution 167
Bootstrapping in statistics 169
Time for action – sampling with numpy.random.choice() 169
Summary 171
Chapter 7: Peeking into Special Routines 173
Sorting 173
Time for action – sorting lexically 174
Time for action – partial sorting via selection for a fast median
with the partition() function 175
Complex numbers 176
Time for action – sorting complex numbers 177
Searching 178
Time for action – using searchsorted 178
Array elements extraction 179
Time for action – extracting elements from an array 179
Financial functions 180
Time for action – determining the future value 181
Present value 183
Time for action – getting the present value 183
Net present value 183
Time for action – calculating the net present value 184
Internal rate of return 184
Time for action – determining the internal rate of return 185
Periodic payments 185
Time for action – calculating the periodic payments 185
Number of payments 186
Time for action – determining the number of periodic payments 186
Interest rate 186
Time for action – figuring out the rate 186
Window functions 187

[v]
Table of Contents

Time for action – plotting the Bartlett window 187


Blackman window 188
Time for action – smoothing stock prices with the Blackman window 189
Hamming window 190
Time for action – plotting the Hamming window 190
Kaiser window 191
Time for action – plotting the Kaiser window 192
Special mathematical functions 192
Time for action – plotting the modified Bessel function 193
sinc 194
Time for action – plotting the sinc function 194
Summary 196
Chapter 8: Assuring Quality with Testing 197
Assert functions 198
Time for action – asserting almost equal 198
Approximately equal arrays 199
Time for action – asserting approximately equal 200
Almost equal arrays 200
Time for action – asserting arrays almost equal 201
Equal arrays 202
Time for action – comparing arrays 202
Ordering arrays 203
Time for action – checking the array order 203
Object comparison 204
Time for action – comparing objects 204
String comparison 204
Time for action – comparing strings 205
Floating-point comparisons 205
Time for action – comparing with assert_array_almost_equal_nulp 206
Comparison of floats with more ULPs 207
Time for action – comparing using maxulp of 2 207
Unit tests 207
Time for action – writing a unit test 208
Nose test decorators 210
Time for action – decorating tests 211
Docstrings 213
Time for action – executing doctests 214
Summary 215

[ vi ]
Table of Contents

Chapter 9: Plotting with matplotlib 217


Simple plots 217
Time for action – plotting a polynomial function 218
Plot format string 219
Time for action – plotting a polynomial and its derivatives 219
Subplots 221
Time for action – plotting a polynomial and its derivatives 221
Finance 223
Time for action – plotting a year's worth of stock quotes 223
Histograms 226
Time for action – charting stock price distributions 226
Logarithmic plots 228
Time for action – plotting stock volume 228
Scatter plots 230
Time for action – plotting price and volume returns with a scatter plot 230
Fill between 232
Time for action – shading plot regions based on a condition 232
Legend and annotations 234
Time for action – using a legend and annotations 235
Three-dimensional plots 238
Time for action – plotting in three dimensions 238
Contour plots 240
Time for action – drawing a filled contour plot 240
Animation 241
Time for action – animating plots 241
Summary 243
Chapter 10: When NumPy Is Not Enough – SciPy and Beyond 245
MATLAB and Octave 245
Time for action – saving and loading a .mat file 246
Statistics 247
Time for action – analyzing random values 247
Sample comparison and SciKits 250
Time for action – comparing stock log returns 250
Signal processing 253
Time for action – detecting a trend in QQQ 253
Fourier analysis 256
Time for action – filtering a detrended signal 256
Mathematical optimization 259
Time for action – fitting to a sine 259
Numerical integration 263

[ vii ]
Table of Contents

Time for action – calculating the Gaussian integral 263


Interpolation 264
Time for action – interpolating in one dimension 264
Image processing 266
Time for action – manipulating Lena 266
Audio processing 268
Time for action – replaying audio clips 268
Summary 270
Chapter 11: Playing with Pygame 271
Pygame 271
Time for action – installing Pygame 272
Hello World 272
Time for action – creating a simple game 272
Animation 275
Time for action – animating objects with NumPy and Pygame 275
matplotlib 278
Time for Action – using matplotlib in Pygame 278
Surface pixels 282
Time for Action – accessing surface pixel data with NumPy 282
Artificial Intelligence 284
Time for Action – clustering points 284
OpenGL and Pygame 287
Time for Action – drawing the Sierpinski gasket 287
Simulation game with Pygame 290
Time for Action – simulating life 290
Summary 294
Appendix A: Pop Quiz Answers 295
Appendix B: Additional Online Resources 299
Python 299
Mathematics and statistics 300
Appendix C: NumPy Functions' References 301
Index 307

[ viii ]
Preface
Scientists, engineers, and quantitative data analysts face many challenges nowadays. Data
scientists want to be able to perform numerical analysis on large datasets with minimal
programming effort. They also want to write readable, efficient, and fast code that is as close
as possible to the mathematical language they are used to. A number of accepted solutions
are available in the scientific computing world.

The C, C++, and Fortran programming languages have their benefits, but they are not
interactive and considered too complex by many. The common commercial alternatives,
such as MATLAB, Maple, and Mathematica, provide powerful scripting languages that are
even more limited than any general-purpose programming language. Other open source
tools similar to MATLAB exist, such as R, GNU Octave, and Scilab. Obviously, they too lack
the power of a language such as Python.

Python is a popular general-purpose programming language that is widely used in the


scientific community. You can access legacy C, Fortran, or R code easily from Python. It
is object-oriented and considered to be of a higher level than C or Fortran. It allows you
to write readable and clean code with minimal fuss. However, it lacks an out-of-the-box
MATLAB equivalent. That's where NumPy comes in. This book is about NumPy and related
Python libraries, such as SciPy and matplotlib.

What is NumPy?
NumPy (short for numerical Python) is an open source Python library for scientific
computing. It lets you work with arrays and matrices in a natural way. The library contains
a long list of useful mathematical functions, including some functions for linear algebra,
Fourier transformation, and random number generation routines. LAPACK, a linear algebra
library, is used by the NumPy linear algebra module if you have it installed on your system.
Otherwise, NumPy provides its own implementation. LAPACK is a well-known library,
originally written in Fortran, on which MATLAB relies as well. In a way, NumPy replaces some
of the functionality of MATLAB and Mathematica, allowing rapid interactive prototyping.
Preface

We will not be discussing NumPy from a developing contributor's perspective, but from more
of a user's perspective. NumPy is a very active project and has a lot of contributors. Maybe,
one day you will be one of them!

History
NumPy is based on its predecessor Numeric. Numeric was first released in 1995 and has
deprecated status now. Neither Numeric nor NumPy made it into the standard Python library
for various reasons. However, you can install NumPy separately, which will be explained in
Chapter 1, NumPy Quick Start.

In 2001, a number of people inspired by Numeric created SciPy, an open source scientific
computing Python library that provides functionality similar to that of MATLAB, Maple, and
Mathematica. Around this time, people were growing increasingly unhappy with Numeric.
Numarray was created as an alternative to Numeric. That is also deprecated now. It was
better in some areas than Numeric, but worked very differently. For that reason, SciPy kept
on depending on the Numeric philosophy and the Numeric array object. As is customary
with new latest and greatest software, the arrival of Numarray led to the development of
an entire ecosystem around it, with a range of useful tools.

In 2005, Travis Oliphant, an early contributor to SciPy, decided to do something about this
situation. He tried to integrate some of Numarray's features into Numeric. A complete
rewrite took place, and it culminated in the release of NumPy 1.0 in 2006. At that time,
NumPy had all the features of Numeric and Numarray, and more. Tools were available to
facilitate the upgrade from Numeric and Numarray. The upgrade is recommended since
Numeric and Numarray are not actively supported any more.

Originally, the NumPy code was a part of SciPy. It was later separated and is now used by
SciPy for array and matrix processing.

Why use NumPy?


NumPy code is much cleaner than straight Python code and it tries to accomplish the
same tasks. There are fewer loops required because operations work directly on arrays
and matrices. The many convenience and mathematical functions make life easier as well.
The underlying algorithms have stood the test of time and have been designed with high
performance in mind.

NumPy's arrays are stored more efficiently than an equivalent data structure in base Python,
such as a list of lists. Array IO is significantly faster too. The improvement in performance
scales with the number of elements of the array. For large arrays, it really pays off to use
NumPy. Files as large as several terabytes can be memory-mapped to arrays, leading to
optimal reading and writing of data.
[x]
Preface

The drawback of NumPy arrays is that they are more specialized than plain lists. Outside the
context of numerical computations, NumPy arrays are less useful. The technical details of
NumPy arrays will be discussed in later chapters.

Large portions of NumPy are written in C. This makes NumPy faster than pure Python code.
A NumPy C API exists as well, and it allows further extension of functionality with the help
of the C language. The C API falls outside the scope of the book. Finally, since NumPy is open
source, you get all the related advantages. The price is the lowest possible—as free as a
beer. You don't have to worry about licenses every time somebody joins your team or you
need an upgrade of the software. The source code is available for everyone. This of course is
beneficial to code quality.

Limitations of NumPy
If you are a Java programmer, you might be interested in Jython, the Java implementation of
Python. In that case, I have bad news for you. Unfortunately, Jython runs on the Java Virtual
Machine and cannot access NumPy because NumPy's modules are mostly written in C. You
could say that Jython and Python are two totally different worlds, though they do implement
the same specifications. There are some workarounds for this discussed in NumPy Cookbook
- Second Edition, Packt Publishing, written by Ivan Idris.

What this book covers


Chapter 1, NumPy Quick Start, guides you through the steps needed to install NumPy on
your system and create a basic NumPy application.

Chapter 2, Beginning with NumPy Fundamentals, introduces NumPy arrays and


fundamentals.

Chapter 3, Getting Familiar with Commonly Used Functions, teaches you the most commonly
used NumPy functions—the basic mathematical and statistical functions.

Chapter 4, Convenience Functions for Your Convenience, tells you about functions that
make working with NumPy easier. This includes functions that select certain parts of your
arrays, for instance, based on a Boolean condition. You also learn about polynomials and
manipulating the shapes of NumPy objects.

Chapter 5, Working with Matrices and ufuncs, covers matrices and universal functions.
Matrices are well-known in mathematics and have their representation in NumPy as well.
Universal functions (ufuncs) work on arrays element by element, or on scalars. ufuncs expect
a set of scalars as the input and produce a set of scalars as the output.

[ xi ]
Preface

Chapter 6, Moving Further with NumPy Modules, discusses a number of basic modules
of universal functions. These functions can typically be mapped to their mathematical
counterparts, such as addition, subtraction, division, and multiplication.

Chapter 7, Peeking into Special Routines, describes some of the more specialized NumPy
functions. As NumPy users, we sometimes find ourselves having special requirements.
Fortunately, NumPy satisfies most of our needs.

Chapter 8, Assuring Quality with Testing, teaches you how to write NumPy unit tests.

Chapter 9, Plotting with matplotlib, covers matplotlib in depth, a very useful Python plotting
library. NumPy cannot be used on its own to create graphs and plots. matplotlib integrates
nicely with NumPy and has plotting capabilities comparable to MATLAB.

Chapter 10, When NumPy Is Not Enough – SciPy and Beyond, covers more details about
SciPy. We know that SciPy and NumPy are historically related. SciPy, as mentioned in the
History section, is a high-level Python scientific computing framework built on top of NumPy.
It can be used in conjunction with NumPy.

Chapter 11, Playing with Pygame, is the dessert of this book. You learn how to create fun
games with NumPy and Pygame. You also get a taste of artificial intelligence in this chapter.

Appendix A, Pop Quiz Answers, has the answers to all the pop quiz questions within
the chapters.

Appendix B, Additional Online Resources, contains links to Python, mathematics, and


statistics websites.

Appendix C, NumPy Functions' References, lists some useful NumPy functions and
their descriptions.

What you need for this book


To try out the code samples in this book, you will need a recent build of NumPy. This means
that you will need one of the Python versions supported by NumPy as well. Some code
samples make use of matplotlib for illustration purposes. matplotlib is not strictly required
to follow the examples, but it is recommended that you install it too. The last chapter is
about SciPy and has one example involving SciKits.

Here is a list of the software used to develop and test the code examples:

‹‹ Python 2.7
‹‹ NumPy 1.9
‹‹ SciPy 0.13

[ xii ]
Preface

‹‹ matplotlib 1.3.1
‹‹ Pygame 1.9.1
‹‹ IPython 2.4.1

Needless to say, you don't need exactly this software and these versions on your computer.
Python and NumPy constitute the absolute minimum you will need.

Who this book is for


This book is for the scientists, engineers, programmers, or analysts looking for a high-quality,
open source mathematical library. Knowledge of Python is assumed. Also, some affinity, or
at least interest, in mathematics and statistics is required. However, I have provided brief
explanations and pointers to learning resources.

Sections
In this book, you will find several headings that appear frequently (Time for action, What just
happened?, Have a go hero, and Pop quiz).

To give clear instructions on how to complete a procedure or task, we use the following
sections.

Time for action – heading


1. Action 1
2. Action 2
3. Action 3

Instructions often need some extra explanation to ensure that they make sense, so they are
followed by these sections.

What just happened?


This section explains the working of the tasks or instructions that you have just completed.

You will also find some other learning aids in the book.

[ xiii ]
Preface

Pop quiz – heading


These are short multiple-choice questions intended to help you test your own understanding.

Have a go hero – heading


These are practical challenges that give you ideas to experiment with what you have learned.

Conventions
In this book, you will find a number of styles of text that distinguish between different
kinds of information. Here are some examples of these styles, and an explanation of
their meaning.

Code words in text are shown as follows: "Notice that numpysum() does not need a
for loop."

A block of code is set as follows:


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

When we wish to draw your attention to a particular part of a code block, the relevant lines
or items are set in bold:
reals = np.isreal(xpoints)
print "Real number?", reals
Real number? [ True True True True False False False False]

Any command-line input or output is written as follows:


>>>fromnumpy.testing import rundocs
>>>rundocs('docstringtest.py')

New terms and important words are shown in bold. Words that you see on the screen, in
menus or dialog boxes for example, appear in the text like this: "Clicking on the Next button
moves you to the next screen."

[ xiv ]
Preface

Warnings or important notes appear in a box like this.

Tips and tricks appear like this.

Reader feedback
Feedback from our readers is always welcome. Let us know what you think about this
book—what you liked or disliked. Reader feedback is important for us as it helps us develop
titles that you will really get the most out of.

To send us general feedback, simply e-mail feedback@packtpub.com, and mention the


book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or
contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support
Now that you are the proud owner of a Packt book, we have a number of things to help you
to get the most from your purchase.

Downloading the example code


You can download the example code files from your account at http://www.packtpub.
com for all the Packt Publishing books you have purchased. 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.

Downloading the color images of this book


We also provide you with a PDF file that has color images of the screenshots/diagrams used
in this book. The color images will help you better understand the changes in the output.
You can download this file from https://www.packtpub.com/sites/default/files/
downloads/NumpyBeginner'sGuide_Third_Edition_ColorImages.pdf.

[ xv ]
Preface

Errata
Although we have taken every care to ensure the accuracy of our content, mistakes do happen.
If you find a mistake in one of our books—maybe a mistake in the text or the code—we
would be grateful if you could report this to us. By doing so, you can save other readers from
frustration and help us improve subsequent versions of this book. If you find any errata, please
report them by visiting http://www.packtpub.com/submit-errata, selecting your book,
clicking on the Errata Submission Form link, and entering the details of your errata. Once your
errata are verified, your submission will be accepted and the errata will be uploaded to our
website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/


content/support and enter the name of the book in the search field. The required
information will appear under the Errata section.

Piracy
Piracy of copyrighted material on the Internet is an ongoing problem across all media.
At Packt, we take the protection of our copyright and licenses very seriously. If you come
across any illegal copies of our works in any form on the Internet, please provide us with
the location address or website name immediately so that we can pursue a remedy.

Please contact us at copyright@packtpub.com with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you
valuable content.

Questions
If you have a problem with any aspect of this book, you can contact us at
questions@packtpub.com, and we will do our best to address the problem.

[ xvi ]
NumPy Quick Start
1
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. This
chapter briefly introduces the IPython interactive shell. 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, you will cover the following topics:

‹‹ Install Python, SciPy, matplotlib, IPython, and NumPy on Windows, Linux,


and Macintosh
‹‹ Do a short refresher of Python
‹‹ Write simple NumPy code
‹‹ Get to know IPython
‹‹ Browse online documentation and resources

Python
NumPy is based on Python, so you need 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 distributions. In this book, we focus on
the standard CPython implementation, which is guaranteed to be compatible with NumPy.

[1]
NumPy Quick Start

Time for action – installing Python on different operating


systems
NumPy has binary installers for Windows, various Linux distributions, and Mac OS X
at http://sourceforge.net/projects/numpy/files/. 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:

‹‹ Debian and Ubuntu: Python might already be installed on Debian and Ubuntu,
but the development headers are usually not. On Debian and Ubuntu, install the
python and python-dev packages with the following commands:
$ [sudo] apt-get install python
$ [sudo] apt-get install python-dev

‹‹ Windows: The Windows Python installer is available at https://www.python.


org/downloads/. On this website, we can also find installers for Mac OS X and
source archives for Linux, UNIX, and Mac OS X.
‹‹ Mac: Python comes preinstalled on Mac OS X. We can also get Python through
MacPorts, Fink, Homebrew, or similar projects.

Install, for instance, the Python 2.7 port by running the following command:
$ [sudo] port install python27

Linear Algebra PACKage (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
that you 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 OS X.

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

[2]
Chapter 1

The Python help system


Before we start the NumPy introduction, let's take a brief tour of the Python help system,
in case you have forgotten how it works or are not very familiar with it. The Python help
system allows you to look up documentation from the interactive Python shell. A shell is
an interactive program, which accepts commands and executes them for you.

Time for action – using the Python help system


Depending on your operating system, you can access the Python shell with special
applications, usually a terminal of some sort.

1. In such a terminal, type the following command to start a Python shell:


$ python

2. You will get a short message with the Python version and other information and the
following prompt:
>>>

Type the following in the prompt:


>>> help()

Another message appears and the prompt changes as follows:


help>

3. If you type, for instance, keywords as the message says, you get a list of keywords.
The topics command gives a list of topics. If you type any of the topic names (such
as LISTS) in the prompt, you get additional information about the topic. Typing q
quits the information screen. Pressing Ctrl + D together returns you to the normal
Python prompt:
>>>

Pressing Ctrl + D together again ends the Python shell session.

What just happened?


We learned about the Python interactive shell and the Python help system.

[3]
NumPy Quick Start

Basic arithmetic and variable assignment


In the Time for action – using the Python help system section, we used the Python shell to
look up documentation. We can also use Python as a calculator. By the way, this is just a
refresher, so if you are completely new to Python, I recommend taking some time to learn
the basics. If you put your mind to it, learning basic Python should not take you more than a
couple of weeks.

Time for action – using Python as a calculator


We can use Python as a calculator as follows:

1. In a Python shell, add 2 and 2 as follows:


>>> 2 + 2
4

2. Multiply 2 and 2 as follows:


>>> 2 * 2
4

3. Divide 2 and 2 as follows:


>>> 2/2
1

4. If you have programmed before, you probably know that dividing is a bit tricky since
there are different types of dividing. For a calculator, the result is usually adequate,
but the following division may not be what you were expecting:
>>> 3/2
1

We will discuss what this result is about in several later chapters of this book. Take
the cube of 2 as follows:
>>> 2 ** 3
8

What just happened?


We used the Python shell as a calculator and performed addition, multiplication, division,
and exponentiation.

[4]
Chapter 1

Time for action – assigning values to variables


Assigning values to variables in Python works in a similar way to most programming
languages.

1. For instance, assign the value of 2 to a variable named var as follows:


>>> var = 2
>>> var
2

2. We defined the variable and assigned it a value. In this Python code, the type of the
variable is not fixed. We can make the variable in to a list, which is a built-in Python
type corresponding to an ordered sequence of values. Assign a list to var as follows:
>>> var = [2, 'spam', 'eggs']
>>> var
[2, 'spam', 'eggs']

We can assign a new value to a list item using its index number (counting starts from
0). Assign a new value to the first list element:
>>> var
['ham', 'spam', 'eggs']

3. We can also swap values easily. Define two variables and swap their values:
>>> a = 1
>>> b = 2
>>> a, b = b, a
>>> a
2
>>> b
1

What just happened?


We assigned values to variables and Python list items. This section is by no means
exhaustive; therefore, if you are struggling, please read Appendix B, Additional Online
Resources, to find recommended Python tutorials.

[5]
NumPy Quick Start

The print() function


If you haven't programmed in Python for a while or are a Python novice, you may be
confused about the Python 2 versus Python 3 discussions. In a nutshell, the latest version
Python 3 is not backward compatible with the older Python 2 because the Python
development team felt that some issues were fundamental and therefore warranted a
radical change. The Python team has committed to maintain Python 2 until 2020. This may
be problematic for the people who still depend on Python 2 in some way. The consequence
for the print() function is that we have two types of syntax.

Time for action – printing with the print() function


We can print using the print() function as follows:

1. The old syntax is as follows:


>>> print 'Hello'
Hello

2. The new Python 3 syntax is as follows:


>>> print('Hello')
Hello

The parentheses are now mandatory in Python 3. In this book, I try to use the
new syntax as much as possible; however, I use Python 2 to be on the safe side. To
enforce the syntax, each Python 2 script with print() calls in this book starts with:
>>> from __future__ import print_function

3. Try to use the old syntax to get the following error message:
>>> print 'Hello'
File "<stdin>", line 1
print 'Hello'
^
SyntaxError: invalid syntax

4. To print a newline, use the following syntax:


>>> print()

5. To print multiple items, separate them with commas:


>>> print(2, 'ham', 'egg')
2 ham egg

[6]
Chapter 1

6. By default, Python separates the printed values with spaces and prints output to the
screen. You can customize these settings. Read more about this function by typing
the following command:
>>> help(print)

You can exit again by typing q.

What just happened?


We learned about the print() function and its relation to Python 2 and Python 3.

Code comments
Commenting code is a best practice with the goal of making code clearer for yourself and
other coders (see https://google-styleguide.googlecode.com/svn/trunk/
pyguide.html?showone=Comments#Comments). Usually, companies and other
organizations have policies regarding code comment such as comment templates. In this
book, I did not comment the code in such a fashion for brevity and because the text in the
book should clarify the code.

Time for action – commenting code


The most basic comment starts with a hash sign and continues until the end of the line:

1. Comment code with this type of comment as follows:


>>> # Comment from hash to end of line

2. However, if the hash sign is between single or double quotes, then we have a string,
which is an ordered sequence of characters:
>>> astring = '# This is not a comment'
>>> astring
'# This is not a comment'

3. We can also comment multiple lines as a block. This is useful if you want to write a
more detailed description of the code. Comment multiple lines as follows:
"""
Chapter 1 of NumPy Beginners Guide.
Another line of comment.
"""
We refer to this type of comment as triple-quoted for obvious reasons.
It also is used to test code. You can read about testing in Chapter 8, Assuring
Quality with Testing.

[7]
NumPy Quick Start

The if statement
The if statement in Python has a bit different syntax to other languages, such as C++ and
Java. The most important difference is that indentation matters, which I hope you are
aware of.

Time for action – deciding with the if statement


We can use the if statement in the following ways:

1. Check whether a number is negative as follows:


>>> if 42 < 0:
... print('Negative')
... else:
... print('Not negative')
...
Not negative

In the preceding example, Python decided that 42 is not negative. The else clause
is optional. The comparison operators are equivalent to the ones in C++, Java, and
similar languages.

2. Python also has a chained branching logic compound statement for multiple tests
similar to the switch statement in C++, Java, and other programming languages.
Decide whether a number is negative, 0, or positive as follows:
>>> a = -42
>>> if a < 0:
... print('Negative')
... elif a == 0:
... print('Zero')
... else:
... print('Positive')
...
Negative

This time, Python decided that 42 is negative.

What just happened?


We learned how to do branching logic in Python.

[8]
Another Random Document on
Scribd Without Any Related Topics
“Sure, that’s so!” agreed the old man. “It’s Pauline’s treasure, right
enough. Ain’t it, Geoffrey?”
“I guess it’s no one else’s,” said Geoffrey, picking up the idea. “I’ll
see to that.”
I could not help smiling at the gratuitous menace in his tone; he
might have been sitting on the treasure-chests already.
At that moment we were startled by an appalling scream, a choking
cry, from Pauline’s stateroom.
We rushed in and stood for a moment transfixed with horror.
Pauline, leaning out of her bunk, was throttling with both hands the
life out of her mother, who had been sitting by the bedside. In a
flash of my first perception of the scene, I saw that the girl had
reverted to her trance-personality. It was Lucia who had that deadly
grip upon the other woman’s throat, Lucia who glared at her with
fiendishly triumphant eyes, Lucia who gloated mockingly in her
foreign accent: “Ah, Teresa!—You think you would take the
Englishman from me—you think you would go away with John
Dawson and the treasure?” She laughed, cruelly exultant. “I think
no, Teresa—I think no—not with the treasure! You can go with that
John Dawson, yes! But not with the treasure! You go and wait for
him—for your John Dawson—I will send him to you—soon—soon!”
Her low laugh was diabolical.
We flung ourselves upon her, but her strength was superhuman. She
seemed utterly oblivious of us, as heedless of our struggles as
though we were not there. Her eyes flashing, her teeth showing, she
continued to jeer at her victim in her foreign voice: “He will come to
you to-night—your John Dawson—as he promised, yes! I will send
him to you——!” Only as we finally tore the almost strangled Mrs.
Vandermeulen from her hands did she suddenly cease to speak. She
sank back upon the bed, swooning into complete unconsciousness.
I drove out the father and son and applied myself to reviving the
mother. I shall not forget the terrible night I had with her, after she
had resuscitated. At length, I had to give her a few drops of
laudanum to get her off to sleep. Pauline slept like a child.
I woke up the next morning to that strange feeling of hushed
stillness which pervades a ship when her engines are at rest after a
long period of unbroken activity. We were pitching heavily, evidently
at anchor, for our upward rise was every now and then suddenly and
jarringly arrested. We had arrived!
I went to look at my patients and found them both suffering from
sea-sickness. This vicious plunging of the yacht was more than their
weak stomachs could stand. I gave them each a steadying draught
and then went on deck.
The two Vandermeulens were on the bridge with the skipper. I
ignored them, instinctively avoiding their certain excitement. Upon
our port bow was a fairly large island, its rocky shore crowned with a
dense tropical foliage. On the other side of us was a small islet,
barren save for a few sparse trees scattered over it, surf breaking
white upon its beaches. Old Providence and its satellite, Santa
Katalina! Between the two islands a strong current was running, with
a heavy ground-swell in which we plunged and kicked, straining at
our cables. No wonder the two ladies were ill, I thought, as the deck
sank sickeningly sideways under my feet.
I went into the saloon and found that the Vandermeulens had
already breakfasted. As I ate my solitary meal, I could hear the
heavy trampling of feet on the deck overhead, and guessed that
they were hoisting outboard the little steam-launch we used when in
harbour.
When I had finished, I went to have another look at Pauline. Her
mother was with her. Mentally, she was completely her normal self,
with apparently no memory even of that trance-personality which
had for the second time surged up in her. But she was feeling very ill
in this violent and disturbing motion of the anchored yacht.
Old Vandermeulen came in.
“Get up and dress, Pauline!” he commanded, brutally, as though
bearing down opposition in advance. “We’re going ashore!”
His wife sprang forward.
“Oh, no, no, William! Don’t take her! Don’t take her!—Don’t tempt
Providence. Don’t go! William! William!” she clung to him in
supplication. “She’s too ill to go! She’s too ill to go, isn’t she,
doctor?”
The old man shook her off.
“Nonsense!” he said roughly. Nevertheless, he turned enquiringly to
me.
I considered the pros and cons dispassionately for a moment. Of
course, the old lady’s fears were mere superstition and did not
influence me in the least.
“Well,” I said, “I think that if Miss Vandermeulen feels equal to the
effort of dressing, it would do her good to get away from the yacht
and walk about on firm land for an hour or two.”
“I should like to,” said Pauline, all docility. “Besides,” she smiled, “I
should like to see for myself if there is any truth in that strange
writing.”
Half an hour later we had, with some difficulty, stowed the ladies—
for the mother insisted on coming also—in the stern-sheets of the
little launch which rose and fell dizzily under the lee of the yacht.
The two Vandermeulens were amidships, ready to give instructions
to the helmsman. I noticed that they had a pick and shovel on
board. I sat close to Pauline. She was looking pale, but the sea-
sickness was in abeyance for the moment and a touch of digitalis I
had given her had stiffened her up.
We sheered off, set a course over the rolling dark blue well toward
the islet we could see as we lifted on the waves. We had anchored
rather on the Old Providence side of the channel dividing the islands,
and the launch was about midway between the two when Pauline,
who had been looking around her with some curiosity, uttered a
sudden ejaculation.
“That’s not the island!” she cried, with a gesture toward Santa
Katalina. “It’s the other one—the big one!” She pointed to Old
Providence. Then she checked herself, a peculiar look of puzzlement
in her face. “I wonder whatever made me say that!” she exclaimed.
“One would think I have been here before—but I can’t have!”
“But that’s Santa Katalina!” objected Geoffrey, pointing to the islet. It
undoubtedly was.
“Wait!” said old Vandermeulen, who had been sharply watching his
daughter for any sign of recognition. “I guess Pauline knows what
she is talking about!”
He stopped the engine and for a few moments we rose and fell idly
upon the waves, while the two men stared across to Old Providence.
“By Jove, yes!” cried Geoffrey suddenly. “Pauline’s right! Look!
There’s Skull Point!”
He indicated, with outstretched hand, a jutting headland whose face
had been weather-sculptured into the unmistakable semblance of a
skull.
“Skull Point it is!” said old Vandermeulen, with such an oath as he
did not usually let come to his daughter’s ears.
In another moment we had gone about and were throbbing quickly
toward the headland. All eyes were fixed on it as we approached.
Geoffrey had produced a compass.
“Look!” he cried. “The three trees! South-west-by-south from Skull
Point!”
Sure enough, in the direction designated, three enormous trees,
evidently hundreds of years old, raised their heads high above the
mass of more recent vegetation.
A quarter of an hour later we were running into a little cove on the
west side of the headland. A ledge of rock, sheltered from the swell,
offered itself as a landing-stage, and we ran alongside and made
fast.
Old Vandermeulen ordered the two members of the yacht’s crew,
who had accompanied us, to remain in the launch. The rest of us
started off into the island, Geoffrey carrying the tools. The three
trees were at no great distance, at the summit of a slope of broken-
down volcanic rock. Geoffrey arrived first.
“No need to worry where to dig, Father!” he shouted. “Here it is—
plain enough!”
Under the centre tree was a cairn of loose stones, more than half
buried under the detritus of many years, it is true, but evidently the
work of men’s hands.
“That’s it, sure!” cried the old man. “First time you’ve seen this
place, Pauline?” he queried, with a touch of grim cynicism.
“Of course!” she replied. “What do you mean, Father?—and yet—”
she hesitated, looking around her—“yet I do have a strange sort of
feeling as though I had been here before. But I can’t have! It’s
absurd!”
Mother and daughter sat down under the shade of the trees whilst
we three set to work to open the cairn. I was as excited as they by
this time, and I helped with a will. The old man, wielding his pick
with the skill of an ex-miner, loosened the stones on the surface. I
rolled away the big ones, and Geoffrey shovelled away the smaller
stuff. At the end of an hour we had made a pretty deep excavation.
We then took it in turns to work with pick and shovel in the hole,
from which we threw up the stones.
Suddenly Geoffrey uttered an exclamation.
“We’re on something!—What’s that, doctor?” He passed me up a
long bone.
“That’s the tibia of a man,” I replied. “I expect you’ll find the rest of
him there.”
“Sure thing!” he said. “Here he is!” He cleared away one or two large
lumps of rock and revealed the grinning skeleton of a man. “Hallo!”
he added, as he bent down to it, “what’s this?”
A long thin stiletto was lying loosely between the fleshless ribs of the
skeleton.
The old man snatched it from him as he plucked it out.
“And by all that’s holy!” he cried, “it’s got her name on it! Look!”
I took it from him. The dagger was of antique pattern, its steel
rusted and corroded but still resilient enough to make it a dangerous
weapon, and on the hilt, still legible, roughly inlaid in silver like the
amateur work of a sailorman, was the name—Lucia!
“I guess she murdered him with that!” said the old man, grimly,
glancing from the stiletto to the skeleton grinning up at us from the
hole where it had so long lain undisturbed. He turned toward where
his daughter sat in the shade of the trees. “Here, Pauline!” he called
to her. “Come and see—your friend the pirate and the knife that
killed him!”
The girl jumped up and ran across to us, all excitement.
“How wonderful!” she said. “It’s like a dream come true!”
At the time, excited as we all were, I did not notice the strangeness
of that spontaneous phrase. She stood upon the edge of the
excavation and took the stiletto with eager curiosity from her father.
She held it in both hands, breast-high, the point toward her, to read
the name upon the hilt.
“Lucia!” she cried, with a strange look toward us, as though dimly
and uncertainly recalling some terrible experience. “Lucia!” She
repeated the name with a peculiar, slow intonation—an intonation of
puzzled half-remembrance.
We stared at her, fascinated. Was our fantastic theory true?
Her gaze lost us, fixed itself into vacancy. Her features changed. An
expression of vague fear—the fear of the hypnotic shrinking at some
invisible danger—came into them. She opened her mouth as though
to speak.
She uttered only an inarticulate cry—a cry of fright as the loose
stones of the excavation slipped from under her. She fell headlong
into the hole, where she lay oddly—ominously—still. I jumped down
after her, lifted her up. The rusty old stiletto, caught under her in her
fall, had driven straight into her heart—broken off at the hilt!

The doctor stopped, looked round upon his audience.


“And the treasure?” queried one of them.
“There was no treasure. There was no more digging that day. We
took the poor girl’s corpse back to the yacht and I thought her
mother would have died as well—or gone out of her mind. She was
screaming to get away from the place. But the old man was not put
off his game so easily. The next day, whilst I stayed on board with
the distracted mother, he and his son went and dug again in that
tragic cairn.
“They brought back all they found—the broken lid of a chest,
branded with the date 1665. That, curiously enough, was
underneath the skeleton, suggesting that the hoard had been rifled
before the man, whoever he was, was killed.”
“A strange story!” commented another of the audience. “And what’s
your hypothesis in explanation, doctor?”
The doctor smiled.
“Well—you can have your choice,” he said. “There is the possibility
that, in a prior existence, Miss Vandermeulen was in fact Lucia, that
she seduced John Dawson into revealing the secret of the treasure,
that she murdered him on the spot and went off with it—and that
the vengeful spirit of the old buccaneer, hovering around these
latitudes, came into touch with her new reincarnation, and, playing
with a fine irony upon that same lust of gold which was responsible
for his murder but of which she was this time entirely innocent, led
her to a death by that same poniard with which she had killed him.
Alternatively, there is the hypothesis that her spontaneous writing
and the impersonation of Lucia were but an automatic dramatization
by her subconsciousness of hints dropped into it by her brother’s
reading of ‘Treasure Island’ and subsequent conversations between
her father and his son, and that her death was a mere coincidence.”
“An incredibly complete coincidence!” said one of the men.
The doctor shrugged his shoulders.
“There was one other curious thing,” he said. “Some years later, in a
history of the buccaneers, I came across a paragraph to the effect
that the island called Old Providence since the eighteenth century
was known to the buccaneers as Santa Katalina, and that only
subsequently was that name transferred to the islet north of it. So
Pauline’s subconscious memory was right! Furthermore, it stated
that the large island, then called Santa Katalina, was seized and
garrisoned by the buccaneers in 1664 under the leadership of a man
named Mansvelt. He sailed off to get recruits, leaving the island in
command of a certain Simon, and died upon the voyage. Simon
surrendered the island to the Spaniards who had besieged it. The
date was 1665.
“Of course, Miss Vandermeulen may have read that paragraph and
subconsciously retained the names—but, for her, it was an
improbable kind of reading. At any rate, she had a curious
knowledge of an out-of-the-way piece of history. As I said, when you
tap the subconsciousness you never know what buried treasure you
may find. Well, I leave you to your hypotheses, gentlemen.” He
stood up, knocked out his pipe. “Good-night!”
A PROBLEM IN REPRISALS
In the dusk of a winter afternoon a battalion of the French
Contingent of the Army of Occupation dispersed to its billets in the
little German village. The Chef-de-bataillon and the médecin-major,
having installed their staffs in their respective bureaux, walked up
the street in search of the quarters which had been chosen for them
in the meanwhile. The scared faces of slatternly women,
obsequiously gesturing the mud-stained French soldiers into
occupation of their cottages, turned to look anxiously at them as
they passed, in evident apprehension of the order which should let
loose a vengeful destruction only too probable to their uneasy
consciences. Here and there a haggard-looking man, an ex-soldier
probably, slunk into his house, out of sight, but the native population
of the village was preponderatingly feminine. The two officers—the
commandant, good-humoured and inclined to rotundity, his eyes
twinkling under brows a shade less gray than his moustache; the
doctor, a middle-aged man, quiet, restrained to curtness in speech
and expression, with eyes that swept sombrely without interest over
his environment—ignored alike the false smiles and the genuinely
alarmed glances of these wives and mothers of their once arrogant
enemies.
A captain came down the street toward them and saluted on near
approach. It was the adjutant of the battalion. He was young and his
natural cheerfulness was enhanced to perpetual high spirits in the
enjoyment of the experiences following upon overwhelming victory.
“We are well housed, mon commandant,” he said joyously, with a
flash of white teeth under his little brown moustache. “Comfort
moderne—presque! Not a château, it is true—but large enough. The
best in the village, in any case. Bedrooms for the three of us, and a
room for our popote. Our baggage is already in, and dinner will be
ready in half an hour. Tout ce qu’il y a de mieux, n’est-ce pas?” He
finished with his young laugh.
The gray eyes of the battalion-commander twinkled at him.
“And the patronne, Jordan?—Old and ugly?”
The young man’s face lit up. He put one finger to his lips and blew
an airy kiss.
“Ah, mon commandant!” he replied in a tone of assumed ecstasy.
“You shall see her! A pearl, a jewel, une femme exquise!—That is to
say,” he added, with a change of note, “she would be if she were not
a femme boche. One almost forgets it, to look at her. But boche or
not, she is young, she is beautiful, and, mon commandant, rarest of
all—she is intelligent!”
The battalion commander laid his hand on the young man’s shoulder
and drew him along with them as they resumed their momentarily
interrupted progress.
“I see I have to congratulate you upon another conquest,” he said,
with amused tolerance. “He is incredible, notre cher Jordan,
Delassus!” he added with a smile to the doctor.
“Je ne dis pas,” protested the young captain with an affectation of
modesty. “But we understand each other and that is already much—
although, unfortunately, she speaks no French and my German lacks
vocabulary. But she made me understand that her husband was an
officer killed in the war. ‘Mann—Offizier—tot—Krieg.’ That’s right,
doctor, n’est-ce pas?—You are the linguist.”
The doctor nodded assent.
“Quite correct. You should make rapid progress under an instructor
so willing to impart interesting information,” he said drily.
The young man protested warmly against the implication.
“Your cynicism is out of place, doctor. I assure you. She is timide—
timide like a frightened bird.—I extorted it from her.—But you shall
see for yourselves. Here we are!”
They were at the end of the village. The young captain led them
through a carriage gateway, sadly in need of a coat of paint, up a
weed-grown drive to a fairly large house, that had once been white
but was now stained with the overflow of gutters long left out of
repair. A belt of trees hid it from the road. The main door, in the
centre of the house with windows on both sides of it, was open, as if
in expectation of them. Wisps of smoke from several of the
chimneys hinted at hospitality in preparation.
As the three of them entered the hall, a young woman appeared on
the threshold of one of the rooms communicating with it. Her natural
slimness was emphasized by a gown of black, and this sombre garb
threw into relief the fair hair which was massed heavily above her
delicate features. It needed, perhaps, the youthful enthusiasm of the
captain to call her beautiful; but her appearance had something of
fragile charm which conferred a distinction rare among German
women. She stood there, a little drawn back from her first
emergence, contemplating them with eyes that evidently sought to
measure the potentiality for mischief in these forced guests. Her
attitude appealed dumbly for protection, so forlorn and frail and
timid was it as she shrunk back in the doorway.
“Introduce us, Jordan!” whispered the battalion-commander to his
subordinate. “On est civilisé, quoi donc!”
The young captain had lost a considerable amount of his assurance.
Rather flustered, he saluted and pointed to his superior.
“Commandant!” then, turning to the other, “Doctor!” he blurted,
clumsily.
Their hostess bowed slightly with a pathetic little smile as the two
officers saluted. The doctor advanced a step.
“Have no fear, gnädige Frau,” he said politely in German. “The war is
over and France does not avenge itself upon women. No harm will
come to you.”
Her face lit up.
“Ach, you speak German!”
“I studied in Germany in my youth, gnädige Frau, and I have not
quite forgotten the language.”
She smiled at him.
“Gewiss nicht!” Then, with a swift change of expression, she
clutched imploringly at his arm. “You will protect me? I am so alone
and frightened!” She hesitated as though seeking a cognate
circumstance in him that should compel his sympathy. “You are
married?”
The polite smile went out of his face. His expression hardened.
“I was, gnädige Frau,” he replied, curtly.
She stared at him, divining that she had blundered upon some
painful mystery. With feminine tact she steered quickly away from it
into the region of safe commonplace. She threw open one of the
doors leading into the hall.
“Here, meine Herren, is the Speisezimmer,” she said in a tone of
colourless courtesy that contrasted with her emotion-charged voice
of a moment before. “It is at your service for your meals. There,”
she pointed to a door at the other side of the hall, “is the Salon—
also at your service. I have had a fire lit in it. Your orderlies are now
in the kitchen. I will send them to you to show you your rooms.” She
inclined her head slightly in sign of farewell and passed out through
a door at the end of the hall.
The young captain looked at his commanding officer.
“Eh bien, mon commandant? What did I tell you? Is she not——?”
His superior interrupted him, a twinkle in his eye.
“She is, mon cher Jordan—but you have not a chance against the
doctor here!” He laughed, clapping the doctor on the back.
The médecin-major frowned. His ascetic features hardened again.
“Mon cher commandant, you do me too much honour,” he said
coldly. “I assure you that there is no living woman who can interest
me.”
“Bah!” said the battalion-commander a trifle fatuously, “moi, je suis
connaisseur dans ces affaires-lá! I am sure that something is going
to happen between you and that woman. I can always feel that sort
of thing in the air like—” he hesitated for an illustration, “like some
people can see ghosts.”
The doctor looked him in the eyes.
“Mon Commandant,” he said, curtly, “if you could see ghosts you
would not feel so sure.”
There was a moment of unpleasant silence. The captain broke it by
shouting for the orderlies.
The three officers were introduced to their rooms and parted to
perform their toilet before dinner.
The meal which followed in the rather overfurnished Speisezimmer
was overshadowed by the gloomy taciturnity of the doctor who
appeared still to resent the battalion-commander’s suggestions of
gallantry. Not all the sprightly sallies of the adjutant, not the
persistent bonhomie of the battalion-commander, resolutely ignoring
any hostility between himself and the doctor, could bring a smile into
that hard-set face with the sombre eyes. Their hostess did not
appear again and was not mentioned between them. When they had
finished, the captain suggested that they should smoke their cigars
in the Salon.
“I feel I want to put my feet on the piano,” he said, with a vague
remembrance of a popular picture, “like the boches at Versailles in
’seventy! To infect our hostess’s curtains with cigar-smoke is a poor
compromise, but it is something! Allons, messieurs!—let us indulge
in hideous reprisals! The boche has devastated our homes—let us
avenge ourselves by spoiling his curtains!”
The battalion-commander looked smilingly across to the doctor.
“Mon cher Delassus, are you for this policy of reprisals?”
The doctor looked up as though startled out of a train of thought.
“Mon commandant, it is a subject on which I dare not let myself
think.”
There was something so harsh in his tone that neither of his
companions could continue their banter. Both looked at the doctor.
They knew little or nothing of his private life, for he had joined the
battalion only just prior to the armistice, but evidently it contained a
tragedy the memory of which they had unwittingly revived. Both
maintained a respectful silence for a few moments. Then the
adjutant rose and went out of the room. He called out to them from
the Salon that a splendid fire awaited them, and the others rose
from the table also.
The battalion-commander laid his hand affectionately upon the
doctor’s shoulder.
“Mon cher,” he said, “forgive me if I have unconsciously wounded
sacred sentiments.”
The doctor pressed the hand that was extended to him. They went
together across the hall into the Salon.
A blazing wood fire fitfully lit up a large room still without other
means of illumination. Jordan explained that he had sent an orderly
for some candles, as Madame had no petroleum for the lamps. The
battalion-commander and the doctor threw themselves luxuriously
into deep armchairs on either side of the fireplace and lit their
cigars. In a few minutes the orderly arrived with the candles. Jordan
fitted them into two large candelabra on the mantelpiece and lit
them.
The eyes of all three officers roved around the apartment. It was,
like the dining-room, rather overfurnished and was particularly rich
in bric-à-brac of all kinds. It was, in fact, overcrowded with porcelain
figures, small mirrors, pictures of moderate size, all sorts of valuable
objects that in almost every case were of easily portable dimensions.
This last attribute leaped simultaneously to the minds of two of
them.
“Mon commandant,” began Jordan, in a humorously affected judicial
tone, “I am penetrated by an unworthy suspicion——!”
“French! Nom d’un nom!” cried the battalion-commander.
“Everything here!—The collection of the burglar boche officer!—
Doctor! You speak German!—Ask that woman——!”
Both were suddenly arrested by the attitude of the doctor. He was
staring in a fixed fascination at a small Buhl clock upon the
mantelpiece. Suddenly he jumped to his feet, snatched down the
clock, and gazed eagerly at the back of it.
“Mon Dieu!” he cried. “This is mine!—it comes from my house!—
Look!”
He showed them an inscription on the back:
[1]“A Jules, pour marquer les heures d’un amour qui ne cessera pas
quand le temps même cessera, de sa Marcelle.”
He stared at them like a lunatic.
“My wife!” he cried. “My wife!—Oh, Marcelle, Marcelle, where are
you? Where are you?”
The others also had risen to their feet. A tense silence followed upon
the wild cry.
The battalion-commander touched the doctor’s arm.
“Mon ami,” he said gently, “—can we help you——?”
The erstwhile sombre eyes of the doctor blazed down upon him, as
though searching for a mortal enemy even in this friend. Then, with
a distinctly apparent effort of will, the anguished man mastered
himself.
“Listen!” he said. “This clock was a present to me from my wife. It
was a love-marriage, ours—we loved, she and I——” he broke off,
his eyes blazing again. Then, with a gesture of the hand as though
he put that from him, he continued: “Before the war I was in
practice at Cambrai. We lived out of the town—in a country house
such as this. In August, 1914, I was mobilized. They sent me to
Lorraine. I left my wife at home, believing her to be safe. You know
what happened. The enemy swept over that part of the country.
Trench-warfare began and my home, all I cared for in the world—my
wife—was in the German lines. I never saw her again. I could never
get any news. I waited four desperate years—and then, when we
advanced, I went to find my home. It simply did not exist—it was a
heap of bricks with a trench through it. My wife—no hint!” He
pressed a hand over his eyes, then stared once more at the clock.
“And now—I find this—here!”
Again there was a tense silence. The battalion-commander broke it
at last.
“Interrogate the woman,” he said, briefly. “She must know
something.”
“It is a pity her husband is dead,” said the captain, with grim
humour. “We could have the pleasure of condemning him by court-
martial, after he had confessed—whatever there is to confess.”
The doctor’s face set hard. He replaced the clock on the mantelpiece
and wrote a few words on a page of his notebook.
“I am going to have the truth,” he said, tearing out the page and
folding it up. “Ring the bell, my dear Jordan.”
An orderly appeared.
“Take this to Madame,” said the doctor, “at once.”
The orderly departed. The three men waited, two of them tingling
with the excitement of this unexpected drama, the third standing
with compressed lips and eyes that seemed to be frowning into a
world which transcended this. He was certainly oblivious of his
companions in the fixity of his thought. At last his lips moved.
“Marcelle! Marcelle!” he murmured. “My love! I am going to know—
and, if need be, to avenge!”
At that moment the door opened and the frail little figure of the
German woman appeared upon the threshold.
“Meine Herren?” she said, in timid enquiry.
The doctor looked up. His companions marvelled to see the
expression of his face change to a smiling courtesy. But there was a
glitter in the usually sombre eyes which spurred their hardly
repressed excitement.
“Will you have the kindness to enter, gnädige Frau?” said the doctor.
His voice was suave, but there was a note in it which his
companions, although they did not understand the words,
recognized as compelling.
The German woman glanced at him apprehensively, and obeyed.
The doctor drew up an armchair for her, close to the fire.
“Will you not seat yourself, gnädige Frau?” he asked still in the suave
voice with the undertone of command.
She inclined her head speechlessly and sat down. They noticed that
her hands were trembling. The doctor motioned his companions to
resume their seats. He himself remained standing, his back to the
fireplace, his form hiding the clock on the mantelpiece from the eyes
of the woman had she looked up. He smiled at her in a reassuring
manner, as she waited dumbly for him to state the reason for his
summons.
“We are very much interested in your collection of porcelain, gnädige
Frau,” he said, smoothly. “It is French, is it not?”
A sudden expression of alarm flitted into her eyes, was banished.
She nodded her head.
“Ja—ja, mein Herr,” she answered hesitatingly. She moistened her
lips. Her hands gripped each other tightly upon her lap.
The battalion-commander and the captain observed her with a
quickened interest. Despite their ignorance of German, the word
“Porzelän” gave them the clue to their comrade’s opening question.
“It is the result of many years’ gradual acquisition, I presume?” he
pursued, in a casual tone.
She shot an upward glance at him from under her eyebrows ere she
replied.
“Ja—mein Herr.”
“It is well chosen,” said the doctor. “I congratulate you on your
knowledge and good taste. Perhaps you would explain some of the
pieces to us—pieces I do not recognize?”
She looked up at him with wide and innocent eyes.
“I cannot, mein Herr. I know nothing about porcelain. It was my
husband’s collection. I keep it in memory of him.”
There was an accent of sincerity in the last phrase which drew a
sharp glance from the doctor.
“Ah,” he said quietly. “He was killed, was he not?”
Her eyes filled with tears, her mouth twitched.
“Killed in one of the very last battles, mein Herr.” She drew a long
sobbing breath and looked wildly at him. “Ach Gott! do not remind
me! do not remind me!” she cried. “He was all I had in the world—
everything—everything! You do not know how good and kind and
loving he was! And now he is gone—he will never come back—never
—never! And I loved him so!” She broke down into sobs, hiding her
face in her hands.
The doctor waited until the crisis had subsided. A diagnosis of
hysteria formed itself in his professional mind.
“So you have no real interest in this collection?” he enquired. “Would
you sell it?”
“Ach, nein—nein!” she answered. “I keep it in memory of him, my
Heinrich, who loved it so.—I feel him here when I dust it and care
for it.” She looked wildly round the room. “I feel him here now!”
The doctor nodded his head in courteous assent to a possibility.
“Did he inherit it?” he asked casually, as though merely pursuing a
conversation which could not, in politeness, be allowed to cease on a
note of distress.
She shook her head.
“Ah, he bought it?”
She moistened her lips nervously ere she replied.
“Yes.”
“Before the war?”
Her face hardened as she answered again.
“Yes.”
There was a moment of silence and then the doctor changed his
position slightly before the mantelpiece.
“And this pretty clock?” he asked, pointing to it. “Did he buy that
also?”
She stared at it and then nodded her head.
“Ja, mein Herr.”
“So!—that is curious. I am particularly interested in that clock,
gnädige Frau. Can you remember where it was bought?”
She hesitated, ventured a scared glance at him, and obviously forced
herself to speech. The two officers involuntarily bent forward in their
interest.
“No, mein Herr.”
She glanced round as though seeking an opportunity for escape.
The doctor repeated his question in a level tone of authority, his
eyes fixed on her.
“You are sure you cannot remember where that clock was bought,
gnädige Frau?”
“Quite sure.” Her breast was heaving. She half rose from her seat.
“Why do you ask me all these questions? Let me go!—Let me go!
You have no right to question me like this! I—I tell you it was bought
—it was all bought!”
The doctor stepped forward with a quick movement, seized her
wrist, and forced her back into her seat.
“I beg of you!” he said in a voice that compelled obedience.
She subsided, trembling in every limb. Her eyes followed his every
movement with the fascinated attention of a frightened animal.
The doctor came close to her, and from her point of view glanced up
to the mantelpiece. Then, stepping back, he arranged the candles so
that the face of the clock, seen from her position, was a disc of
bright reflection.
Without a word but with a deliberation which awed even the
watching officers by its inflexible though mysterious purpose, he
turned to her once more, and, with the gently firm touch of a
medical man, posed her head so that she looked straight before her.
Paralyzed under his masterful dominance, she submitted plastically.
She was too frightened to utter a sound. Only her eyes widened as
she saw him produce a heavy revolver.
“Now, gnädige Frau!” he said, and his voice, though passionless, was
intense in its expression of level will-power, “do not move your head!
Look up—under your eyebrows. You see that clock? Look at it—
continue to look at it!—If you take your eyes off it for one fraction of
a second I shall shoot you dead! You are looking at it? It marks a
quarter to eight. When it strikes eight you will tell me quite truthfully
how you came by it!”
He ceased. The young woman, her face white with terror, her mouth
twitching, her nostrils distended, sat motionless, staring up under
her eyebrows at the face of the clock.
There was a dead silence in the room. The minutes passed. The
young woman did not move a muscle. Her wide-open eyes fixed on
the clock, she seemed to stiffen into a cataleptic rigidity.
The doctor put aside his revolver. He approached her, took one of
her wrists and lifted her hand from her lap. It lay limply in his.
“You are feeling sleepy,” he said in his level, positive voice. “You are
going to sleep. My voice is sounding muffled and far away—but you
will still hear it. You are losing the sense of your surroundings—but
you still see that clock face. You cannot help but see it. And when it
strikes eight you are going to tell the truth.” He dropped the hand
which fell lifelessly again upon her lap.
The young woman sat motionless as a statue. Her breathing
changed to the deep respirations of sleep, although her eyes
remained wide open.
The clock struck eight. At the last of its thin, silvery notes the young
woman shuddered. Her lips moved.
“My husband sent it to me,” she said in a toneless, dreamy voice.
“When?” asked the doctor.
“In 1915.”
“From whence?”
“From the front.”
“Do you know the place?”
“No.”
“You are quite sure?”
“Quite sure.”
“And all these other things?”
“My husband sent them to me.”
“From France?”
“Yes.”
“How did he become possessed of them?”
“He took them out of houses.”
There was a pause in which the young woman did not move in the
slightest. She appeared like some oracular statue waiting for the
next question.
“Why did you lie to me?” asked the doctor in his level voice.
“Because you would have thought my husband a thief, and I am so
proud of him.”
“Can you be proud of him, knowing that he was a thief?”
“Yes,” came the dreamy answer. “It was not his crime. He sent these
things to me because I asked him for them and he loved me.”
“You asked him to send you these things? Why?”
“Because all the other officers’ wives were having things sent to
them.”
“So! Your husband would not have taken them if you had not asked
for them?”
“No. He only took them to give me pleasure. He never thought of
anybody but me. That is why I love him so—why I shall always love
him.”
The doctor bit his lip, and hesitated for a moment.
“You do not think your husband would have offered violence to a
woman in the house where he got this clock?”
“No. He loved me too much. He never thought of any woman but
me. I am sure of it. He was an ideal man, my Heinrich—always
gentle, always loving, always faithful.” She paused a moment before
continuing. “It is cruel of you to make me realize how much I love
him!”
The doctor stood over her, contemplating her, his brows wrinkled in
a puzzled frown. His comrades looked at him enquiringly. He ignored
them. The young woman, having ceased to speak, remained
motionless and upright on her chair. The only sound in the room was
the ticking of the clock.
Suddenly the doctor’s brows cleared in an evident decision. He lifted
the young woman’s hand again as he spoke in his level, positive
voice. His face was very grave.
“You are asleep. But you are going into a very much deeper sleep—a
sleep so profound that it takes you far out of this time and place.
Nevertheless you will remain in touch with me and you will hear my
voice. But everything else is going from you. You are now released
from the limitations of this body. You are on a plane from which you
can enter into any time and place that I shall command.”
He dropped her hand and, with his finger-tips, closed the lids over
her eyes. Her body still remained upright in its trancelike rigidity.
“What do you see?” he asked.
“Nothing,” came the dreamy answer.
“Where are you?”
“I do not know—I—I am nowhere, I think,” she said with hesitation.
“I—I—oh, do not keep me like this!” There was a new note of
anxiety in her voice.
“Wait a moment,” said the doctor. He turned to the mantelpiece,
took down the clock, placed it on her lap, and clasped her hands
about it.
“Now,” he said in his quiet, tense tones, “you are in touch with that
clock. I want you to go into the time and place when that clock had
another owner—before your husband had it. Focus yourself upon it.
Go into the room where it stands.”
The young woman’s eyelids twitched flickeringly but otherwise her
rigid attitude was unmodified.
“Yes,” she said, in a slow and doubtful tone, “yes——”
“What do you see?” asked the doctor. His lips compressed
themselves firmly after the words, the muscles of his lean jaw stood
out, in the intense effort of his will to keep emotion under control, to
avoid an unconscious suggestion of ideas.
“I see a salon,” said the young woman dreamily, “a salon with
French windows opening on to a lawn. There is a grand piano in it—
and a young woman seated at the piano. She is dark—young—oh,
she is very beautiful! She keeps on looking at the clock—the clock is
on the mantelpiece between two bronze statuettes. She is expecting
somebody——”
“Yes?” said the doctor, crouching over her, his fists clenched in a
spasm of supremely willed self-control, his breath coming in the
quick gasps enforced by that tumultuous beating of the heart he
could not command.
“Yes?—Go on!”
“She hears a footstep—she jumps up from the piano. A man comes
into the room—a civilian. She throws her arms about him and kisses
him. She leads him across to the mantelpiece and takes up the
clock. She puts it into his hands—she is showing him something on
the back of it, something written! They kiss again. They are in love
these two—how she loves him! I can feel that—I can feel her love
vibrating in me!” She paused dreamily. “I know what real love is—
and she loves him like that——”
“The man?” asked the doctor, his eyes wild. “The man?—describe
him!”
“His back is turned to me—I cannot see his face. Ah, he turns round.
The man is—you!”
The doctor looked as though he were going to collapse. His
companions watched him, fascinated, completely mystified, trying to
guess at the drama their ignorance of the language hid from them.
He mastered himself with a mighty effort.
“Yes,” he said. “You have the place right—but not the time. Go on a
year—more than a year! Go on to the time when this clock passed
out of that woman’s possession!”
“More than a year!” she repeated dreamily. “I—I must sleep—I
cannot——” She was silent for a few moments. “Yes—yes—I see the
room again. The young woman is in it. She is seated at a little table
—writing. She looks up—Oh, how sad and pale she is!—but she is
still very beautiful. I am so sorry for her—she is so unhappy—and
she is still in love, I can still feel it vibrating in me. She is picking up
a photograph—she kisses it—it is yours!—she kisses it again and
again. Why are you not with her? I feel that you are a great distance
off—she does not know where you are. That worries her, because
she loves you so.” She stopped.
“Go on,” said the doctor sternly. “What do you see next?”
“She puts away her writing hurriedly. She is frightened of something
—someone is coming, I think—yes! The door opens—a soldier—no, a
German officer! Oh, she is frightened of him, but she is brave! She
stands up as he comes toward her. She draws back from him—he is
between her and the door. He puts out his hands, tries to hold her—
Ach!” her voice rose to a scream, “it is Heinrich!”
“Go on!” commanded the doctor. “Go on! What do you see?” His
voice was terrible in its inexorability.
“Oh no, no!” she whispered. “No! Don’t make me see! don’t make
me see! I don’t want to—I don’t want to—Ach, Heinrich, Heinrich!”
Her voice came on a note of anguish. “I cannot bear it!”
The doctor frowned at the rigid figure with closed eyes that began to
sway slightly to and fro upon its chair. Her face was drawn with a
suffering beyond expression.
“See!” he commanded. “And tell me what you see!”
“Oh!” she moaned, “you are cruel—cruel! I do not want to see! I do
not want to look!”
“You must!”
“Oh!” Evidently she surrendered helplessly. She commenced in a
fatigued, dreary voice: “They are there together—the two of them!
That beautiful woman—oh, I hate her now, I hate her!—Ach,
Heinrich, have you forgotten me?” It was as if she called to him. “He
does not hear me. His eyes are fixed on the woman.” She continued
in short panting sentences uttered with increasing horror. “She is
retreating from him—further and further back. He is following her.
Oh, something terrible is going to happen—it is in the air—I feel it—
something horrible!—What?—Ah, he is trying to kiss her! My
Heinrich! Oh, how dreadful, how dreadful!—Oh, don’t make me see
any more—don’t make me see any more!—He has got her in his
arms—she is struggling. Oh, I can’t look—I will not look!—Oh,
Heinrich, and I loved you so!” Her voice fell from the scream of a
nightmare to a plaintive moaning. “Oh, no more—no more! I can
bear no more!”
“Look!—Look to the very end!”
The doctor’s comrades shuddered at his aspect as he crouched over
her, seeming as though he were trying to peer with her eyes into
some scene of horror they could not even imagine.
The young woman’s face was a mask of agony.
“Oh, you torture me,” she moaned, “you torture me—I see, and I do
not want to see—oh, I do not want to see——”
“What do you see?”
“They are struggling together!—She fights desperately—what a wild
cat she is! He is pinning her arms to her sides with his embrace—she
throws her head back, back, to escape him. Ah! She has broken
away! She runs to the table. What is she going to do?” The seer’s
voice rose in acute alarm. “Ach, a revolver! Oh, no, no!” The
ejaculation was a vehement and agonized protest. “Heinrich! Oh,
leave her—leave her!—No, he laughs at her as he follows—and she
is so desperate. Ah, he has got her up in a corner—he has seized her
again—she is crying out—it is a name—she cries it again and again
——”
“What name?”
“I hear it! Jules!—Jules!—that is it—Jules! Oh, what a tone of
despair!”
The doctor closed his eyes and swayed. Then, mastering himself
with a superhuman effort, he said hoarsely:
“Go on!—To the end!”
“I cannot see plainly—they are struggling still. Ach! the revolver! She
has fired! I see the thin smoke in the air.—What has happened? He
has her in his arms—he stumbles with her.—Ach, she is dead! She
has shot herself. He stretches her out on the floor—he is bending
over her—Ach, Heinrich, Heinrich, you have broken my heart!” She
wailed as if from the depths of a wretchedness beyond all solace.
“You have killed my love for ever! I hate you, I hate you, I hate you
as long as I live—I hate myself for having loved you! Faithless,
despicable brute!”
She finished in a tone of fierce vindictiveness, a resentment, at once
horrified and implacable, of unforgivable wrong.
But the doctor no longer heeded her. Hands to his brow, eyes
closed, he reeled away from her.
“Mon Dieu! Mon Dieu!” he groaned. “Marcelle, Marcelle! How shall I
avenge you?”
He glanced at the now silent and still rigid figure of the young
woman. Tears were trickling down her cheeks from the closed eyes.
Her trance was unbroken. She sat still nursing the clock.
Then, with a deep breath, he drew himself erect. The jaw that
expressed his powerful will set hard again. His two companions
looked with horror upon the dreadful pallor of that face from which
two fierce eyes blazed. A little laugh from him. It was a sickening
mockery of mirth.
“Mes amis!” he said. “You asked me a little time ago what I thought
of the policy of reprisals. I ask you that question now. That young
woman, in a hypnotic trance, has just described to me, as though
she had seen it acted before her eyes, the suicide of my wife. She
killed herself rather than be outraged by that woman’s husband. In
her waking life the young woman is, of course, totally ignorant of
the event. In her waking life she adores the memory of her dead
husband as of a perfect and faithful lover. Now, in her hypnotic
state, she loathes him—her love has turned to bitter jealous hatred.
She despises him. In fact, she feels toward him just as she would
have felt had she witnessed the scene that destroyed my life’s
happiness. It rests with me to call her back to waking life, totally
ignorant of her husband’s crime, adoring him as before—or to leave
her in an agony of shattered love. Virtually, her husband murdered
my wife. Her memory of him is the only thing that I can touch. Shall
I leave it sacred? Or shall I, justly, kill it?—What do you say?—It is a
pretty little problem in reprisals for you!”
His comrades stared at him in horrified astonishment.
“But,” cried the battalion-commander, “are you sure——”
“Look at her!” replied the doctor.
The young woman still sat rigidly upright. Her face was drawn with
anguish. Heavy tears rolled ceaselessly from under the closed
eyelids. She sobbed quietly in a far-off kind of way that was
nevertheless eloquent of an immense despair.
“She sees what happened——?” queried the captain in an
incredulous and puzzled tone.
“Three years ago. She is looking at it now,” asserted the doctor. “She
sees her husband bending over my dead wife.—Come, messieurs, let
me have your verdict!” He seemed to be experiencing a grim,

You might also like