Introduction to Python for Science and Engineering Second Edition David J. Pine All Chapters Instant Download
Introduction to Python for Science and Engineering Second Edition David J. Pine All Chapters Instant Download
https://ebookultra.com
https://ebookultra.com/download/introduction-to-
python-for-science-and-engineering-second-edition-
david-j-pine/
https://ebookultra.com/download/engineering-mechanics-an-introduction-
to-dynamics-4th-edition-david-j-mcgill/
ebookultra.com
https://ebookultra.com/download/python-programming-an-introduction-to-
computer-science-john-m-zelle/
ebookultra.com
https://ebookultra.com/download/introduction-to-biomedical-
engineering-3ed-edition-enderle-j/
ebookultra.com
https://ebookultra.com/download/introduction-to-computing-and-
programming-in-python-a-multimedia-approach-mark-j-guzdial/
ebookultra.com
Introduction to Plasma Technology Science Engineering and
Applications 1st Edition John Ernest Harry
https://ebookultra.com/download/introduction-to-plasma-technology-
science-engineering-and-applications-1st-edition-john-ernest-harry/
ebookultra.com
https://ebookultra.com/download/introduction-to-psycholinguistics-
understanding-language-science-matthew-j-traxler/
ebookultra.com
https://ebookultra.com/download/introduction-to-fire-in-california-
second-edition-david-carle/
ebookultra.com
https://ebookultra.com/download/introduction-to-materials-science-and-
engineering-a-guided-inquiry-1st-edition-elliot-p-douglas/
ebookultra.com
https://ebookultra.com/download/introduction-to-chemical-engineering-
thermodynamics-7rd-ed-edition-j-m-smith/
ebookultra.com
Introduction to Python for Science and Engineering
Second Edition David J. Pine Digital Instant Download
Author(s): David J. Pine
ISBN(s): 9781032673950, 1032673958
File Details: PDF, 23.39 MB
Year: 2024
Language: english
Introduction to
Python for Science and
Engineering
Introduction to Python for Science and Engineering offers a quick and incisive
introduction to the Python programming language for use in any science or
engineering discipline. The approach is pedagogical and “bottom up,” which
means starting with examples and extracting more general principles from that
experience. No prior programming experience is assumed.
Readers will learn the basics of Python syntax, data structures, input and output,
conditionals and loops, user-defined functions, plotting, animation, and visual-
ization. They will also learn how to use Python for numerical analysis, including
curve fitting, random numbers, linear algebra, solutions to nonlinear equa-
tions, numerical integration, solutions to differential equations, and fast Fourier
transforms.
Readers learn how to interact and program with Python using JupyterLab and
Spyder, two simple and widely used integrated development environments.
All the major Python libraries for science and engineering are covered, includ-
ing NumPy, SciPy, Matplotlib, and Pandas. Other packages are also introduced,
including Numba, which can render Python numerical calculations as fast as
compiled computer languages such as C but without their complex overhead.
David J. Pine has taught physics and chemical engineering for over 40 years
at four different institutions: Cornell University (as a graduate student), Haver-
ford College, UCSB, and NYU, where he is a Professor of Physics, Mathematics,
and Chemical & Biomolecular Engineering. He has taught a broad spectrum of
courses, including numerical methods. He does research on optical materials
and in experimental soft-matter physics, which is concerned with materials such
as polymers, emulsions, and colloids.
Intelligent Data-Driven Systems and Artificial Intelligence
Series Editor: Harish Garg
Cognitive Machine Intelligence
Applications, Challenges, and Related Technologies
Inam Ullah Khan, Salma El Hajjami, Mariya Ouaissa, Salwa Belqziz and
Tarandeep Kaur Bhatia
David J. Pine
Designed cover image: David J. Pine
MATLAB• and Simulink• are trademarks of The MathWorks, Inc. and are used with per-
mission. The MathWorks does not warrant the accuracy of the text or exercises in this
book. This book’s use or discussion of MATLAB• or Simulink• software or related prod-
ucts does not constitute endorsement or sponsorship by The MathWorks of a particular
pedagogical approach or particular use of the MATLAB• and Simulink•software.
Second edition published 2025
by CRC Press
2385 NW Executive Center Drive, Suite 320, Boca Raton FL 33431
Reasonable efforts have been made to publish reliable data and information, but the author
and publisher cannot assume responsibility for the validity of all materials or the conse-
quences of their use. The authors and publishers have attempted to trace the copyright
holders of all material reproduced in this publication and apologize to copyright holders if
permission to publish in this form has not been obtained. If any copyright material has not
been acknowledged please write and let us know so we may rectify in any future reprint.
Except as permitted under U.S. Copyright Law, no part of this book may be reprinted,
reproduced, transmitted, or utilized in any form by any electronic, mechanical, or other
means, now known or hereafter invented, including photocopying, microfilming, and re-
cording, or in any information storage or retrieval system, without written permission
from the publishers.
For permission to photocopy or use material electronically from this work, access www.
copyright.com or contact the Copyright Clearance Center, Inc. (CCC), 222 Rosewood
Drive, Danvers, MA 01923, 978-750-8400. For works that are not available on CCC please
contact [email protected]
DOI: 10.1201/9781032673950
CHAPTER 1 Introduction 1
1.1 INTRODUCTION TO PYTHON FOR SCIENCE AND
ENGINEERING 1
1.2 INSTALLING PYTHON 3
vii
viii Contents
Index 413
Preface to First Edition
The aim of this book is to provide science and engineering students a practi-
cal introduction to technical programming in Python. It grew out of notes I
developed for various undergraduate physics courses I taught at NYU. While
it has evolved considerably since I first put pen to paper, it retains its original
purpose: to get students with no previous programming experience writing
and running Python programs for scientific applications with a minimum of
fuss.
The approach is pedagogical and “bottom up,” which means starting with
examples and extracting more general principles from that experience. This
is in contrast to presenting the general principles first and then examples of
how those general principles work. In my experience, the latter approach is
satisfying only to the instructor. Much computer documentation takes a top-
down approach, which is one of the reasons it’s frequently difficult to read and
understand. On the other hand, once examples have been seen, it’s useful to
extract the general ideas in order to develop the conceptual framework needed
for further applications.
In writing this text, I assume that the reader:
• is familiar with how to get around a Mac or PC at a very basic level; and
This book introduces, in some depth, four Python packages that are im-
portant for scientific applications:
xvii
xviii Preface to First Edition
The aim of the second edition remains the same as the first: to provide science
and engineering students a practical introduction to technical programming
in Python. This new edition adds nearly 100 pages of new material.
Among the changes, the concept of an object is developed more thor-
oughly, starting in Chapter 2 with the discussion of variables and assignment.
This perspective is continued throughout the text as the various aspects of ob-
jects are revealed and developed. The chapter on Python classes, now Chapter
10, has been completely rewritten with new examples. Here, we emphasize the
concept of encapsulation and its use in science and engineering.
Chapter 3 on the Spyder and Jupyter Lab integrated development environ-
ments (IDEs) is new. Some of the material on the Spyder IDE can be found in
the First Edition, but it has been updated and expanded in this edition. The
material on the Jupyter Lab IDE is entirely new, as Jupyter Lab has developed
significantly since the first edition and now offers a compelling IDE.
New examples have been added to Chapter 6 on conditionals and loops.
The chapter also includes a new section on exception handling.
The introduction of functions has been moved so that it now occurs be-
fore the chapter on plotting. Type hints, new to Python since the first edition,
are discussed. The subtle subject of namespace and scope and its relation to
functions has been expanded significantly.
The chapter on curve fitting has been eliminated. That material is now
covered in Chapters 7 and 9.
New material has been added to Chapter 8 on plotting, including an in-
troduction to the Seaborn package. New examples have been added, includ-
ing using two separate scales for a single axis, plots with insets, vector field
(quiver) plots, and plotting with polar coordinates.
Chapter 9 on the NumPy and SciPy packages has been expanded to in-
clude new material on interpolating and smoothing splines. Several updates
in various NumPy and SciPy packages have been incorporated into the text,
including changes in NumPy’s random number and polynomial packages.
xxi
xxii Preface to Second Edition
David Pine has taught Physics and Chemical Engineering for more than 40
years at four different institutions: Cornell University (as a graduate student),
Haverford College, UCSB, and NYU, where he is a Professor of Physics, Math-
ematics, and Chemical and Biomolecular Engineering. He has taught a broad
spectrum of courses, including numerical methods. He does research on opti-
cal materials and soft-matter physics, which is concerned with materials such
as polymers, emulsions, and colloids.
xxiii
CHAPTER 1
Introduction
DOI: 10.1201/9781032673950-1 1
2 Introduction to Python for Science and Engineering
Don’t worry if you don’t know exactly what these terms mean.1 Their pri-
mary significance for you is that you can write Python code, test it, and use it
quickly with a minimum of fuss.
One advantage of Python compared to MATLAB® is that it is free. It can be
downloaded from the web and is available on all the standard computer plat-
forms, including Windows, macOS, and Linux. This also means that you can
use Python without being tethered to the internet, as required for commercial
software tied to a remote license server.
Another advantage is Python’s clean and simple syntax, including its im-
plementation of object-oriented programming. This should not be discounted;
Python’s rich and elegant syntax renders many tasks that are difficult or arcane
in other languages more straightforward and understandable in Python.
A significant disadvantage is that Python programs can be slower than
compiled languages like C. For large-scale simulations and other demanding
applications, there can be a considerable speed penalty in using Python. In
these cases, C, C++, or Fortran are recommended, although intelligent use of
Python’s array processing tools in the NumPy module can significantly speed
up Python code. Alternatively, several new tools have recently appeared that
can be used to speed up certain numerical computations in Python signifi-
cantly, often by one or two orders of magnitude. These are discussed in Chap-
ter 13. Another disadvantage is that, compared to MATLAB®, Python is less
well-documented. This stems from the fact that it is public open source soft-
ware and thus depends on volunteers from the community of developers and
users for documentation. The documentation is freely available on the web
but is scattered among a number of different sites and can be terse. This book
will acquaint you with the most commonly used websites. Search engines like
Google can help you find others.
You are not assumed to have had any previous programming experience.
However, the purpose of this manual isn’t to teach you the principles of com-
puter programming; it’s to provide a very practical guide to getting started
with Python for scientific computing. Once you see some of the powerful
tasks you can accomplish with Python, perhaps you will be inspired to study
computational science and engineering, as well as computer programming, in
greater depth.
1
Appendix B contains a glossary of terms you may find helpful.
Introduction 3
Launching Python
In this chapter, you learn about IPython, an interface that allows you
to use Python interactively with tools optimized for mathematical and
computational tasks. You learn how to use IPython as a calculator to
add, subtract, multiply, divide, and perform other common mathemat-
ical functions. You also learn the basic elements of the Python program-
ming language, including functions, variables, and scripts, which are
rudimentary computer programs. You are introduced to Python mod-
ules, which extend the capabilities of the core Python language and al-
low you to perform advanced mathematical tasks. You also learn some
new ways to navigate your computer’s file directories. Finally, you learn
how to get help with Python commands and functions.
4 DOI: 10.1201/9781032673950-2
Launching Python 5
you are running Windows, launch the Anaconda Powershell Prompt application
from the Start menu. Under Linux, you can open the Terminal application by
pressing <ctrl + alt + T>.
After launching a terminal application, type jupyter qtconsole at the
terminal prompt and press <return>. This launches a particularly powerful
version of the IPython shell called the Qt Console. Alternatively, instead of
launching a terminal, you can launch Qt Console directly from the Anaconda-
Launcher app that is downloaded with the Anaconda Python Distribution. The
Qt Console for IPython will be used throughout this text. It should look like
the window in Figure 2.1. You should see the default input prompt of the
IPython shell, which looks like this:
In[1]:
This is not what you want either. Type quit() after the >>> prompt to quit the
Python shell and return to the system terminal. By the way, you can also type
quit() to quit either of the IPython shells and return to the system terminal.
6 Introduction to Python for Science and Engineering
indicates that the IPython shell is running and ready to receive input from
the user (you!). By typing commands at the prompt, IPython can be used to
perform various tasks, such as running programs, performing arithmetic, and
creating and moving files around on your computer.
Before getting started, we note that, like most modern computer lan-
guages, Python is case sensitive. That is, Python distinguishes between upper-
and lower-case letters. Thus, two words spelled the same but having different
letters capitalized are treated as different names in Python. Please keep that in
mind in all that follows.
Python returns the correct product, as expected. You can do more complicated
calculations:
In[2]: 6 + 21 / 3
Out[2]: 13.0
Notice that the effect of the parentheses in In[3]: (6 + 21) / 3 is to cause the
addition to be performed first and then the division. Without the parenthe-
ses, Python will always perform the multiplication and division operations be-
fore performing the addition and subtraction operations. The order in which
arithmetic operations are performed is the same as for most calculators: expo-
nentiation first, then multiplication or division, then addition or subtraction,
then left to right.
Launching Python 7
1. Integers in Python are simply, as their name implies, integers. They can
be positive or negative and can be arbitrarily long. In Python, a number
is automatically treated as an integer if it is written without a decimal
point. This means that 23, written without a decimal point, is an integer,
and 23., written with a decimal point, is a floating point number. Here
are some examples of integer arithmetic:
In[4]: 12 * 3
Out[4]: 36
In[5]: 4 + 5 * 6 - (21 * 8)
Out[5]: -134
In[6]: 11 / 5
Out[6]: 2.2
In[8]: 9734828*79372
Out[8]: 772672768016
For the binary operators +, -, *, and //, the output is an integer if the
inputs are integers. The output of the division operator / is a floating
point number (as of version 3 of Python). The floor division operator //
must be used if an integer output is desired when dividing two integers.
2. Floating point numbers are essentially rational numbers and can have
a fractional part; integers, by their very nature, have no fractional part.
In most versions of Python, floating point numbers go between approx-
imately ±2 × 10−308 and ±2 × 10308 . Here are some examples of floating
point arithmetic:
In[9]: 12. * 3
Out[9]: 36.0
In[10]: 12 / 3.
Out[10]: 4.0
In[11]: 5 ** 0.5
Out[11]: 2.23606797749979
In[12]: 5 ** (1/2)
Out[12]: 2.23606797749979
In[13]: 11. / 5.
Out[13]: 2.2
In[14]: 11. // 5.
Out[14]: 2.0
In[15]: 11. % 5.
Out[15]: 1.0
Note that the result of any operation involving only floating point num-
bers as inputs is another floating point number, even in cases where the
floor division // or remainder % operators are used. The last output illus-
trates an alternative way of writing floating point numbers as a mantissa
followed by e or E followed by a power of 10: so 1.23e-12 is equivalent
to 1.23 × 10−12 .
Notice also that multiplying or dividing a floating point number by an
integer produces a floating point number.
Launching Python 9
Notice that 2.5-3j**2 and (2.5-3j)**2 give different results. You need to
enclose the real and imaginary parts of a complex number in parenthe-
ses if you want exponentiation to operate on the entire complex number
and not simply on the imaginary part. It works similarly with multipli-
cation and division of complex numbers, so be sure to enclose the en-
tire complex number with parentheses if you wish to multiply or divide
complex numbers.
If you multiply an integer by a floating point number, the result is a float-
ing point number. If you multiply a floating point number by a complex
number, the result is a complex number. Python promotes the result to
the most complex of the inputs.
has an ID, which is just its location in your computer’s memory. We can de-
termine the ID of an object using Python’s id function.
In[21]: id (52)
Out[21]: 140294301609872
In[22]: id (241.3)
Out[22]: 140293508419248
In[23]: id (3+7j)
Out[23]: 140293508416368
The next thing to know is that every object has a type, which can be as-
certained using the function type. So, what are the types of the numbers we
introduced above?
In[24]: type (72)
Out[24]: int
The results are not too surprising: int for integers, float for floating point
numbers, and complex for complex numbers.
An object’s type defines how it interacts with other objects. For exam-
ple, you can freely add, subtract, multiply, and divide objects of the types int,
float, and complex, as illustrated above. On the other hand, you can’t multiply
float and complex types by a string type such as “dog” (we introduce strings in
Chapter 4). Trying to do so will result in an error message. Surprisingly, you
can multiply strings by int types, but we defer that discussion to Section 4.1.
Python binds the variable name a to the integer object 32. The equals sign = is
the assignment operator, and its function is to bind the variable name on the
left side to the object on its right side.
Consider the following code:
In[2]: leg_a = 3.7
Launching Python 11
19.53
leg_a = 19.53
In[5]: hypontenuse
Out[5]: 9.087353850269066
The first two statements bind the variable names leg_a and leg_b to the float
objects 3.7 and 8.3, respectively. The third statement performs the calculation
to the right of the equals sign and then binds the variable name hypotenuse to
the resulting float object 9.087353850269066. Note that Python binds the result
of the calculation, not the calculation itself, to the variable hypotenuse. There-
fore, if we reassign the value of leg_a to a new value, the value of hypotenuse
does not change, as demonstrated here.
In[6]: leg_a = 19.53
In[7]: hypotenuse
Out[7]: 9.087353850269066
When we write leg_a = 19.53, Python reassigns the variable name leg_a to
a new float object 19.53, as illustrated in Figure 2.2. The old object, in this
case, the float 3.7, is still in memory. Eventually, Python gets rid of it to free
up memory; this process is called garbage collection and occurs behind the
scenes so that you do not need to worry about it.
The assignment operator “=” in Python is not equivalent to the equals
sign “=” you are accustomed to in algebra. Consider the following sequence
of commands.
In[8]: a = 5
12 Introduction to Python for Science and Engineering
In[9]: a = a + 2
In[10]: a
Out[10]: 7
In[12]: c += 3
In[13]: c
Out[13]: 7
In[14]: c *
= 3
In[15]: c
Out[15]: 21
In[16]: d = 7.92
In[17]: d /= -2
In[18]: d
Out[18]: -3.96
In[19]: d -= 4
In[20]: d
Out[20]: -7.96
By the way, %=, **=, and //=, are also valid operators. Verify in the IPython
console that you understand how the above operations work.
Python also allows you to make multiple variable assignments in a single
statement
In[21]: p, q, r = 32.1 , 81.6 , 111.6
see if you were able to predict the correct results. The key thing to remember
is that Python evaluates the right-hand side of the equation before assigning
the results to the left-hand side.
Finally, please note that the same object can have multiple names. For ex-
ample, in the following code, a and b point to (i.e., are bound to) the same
object, which you can verify by checking the ID of each of them.
In[22]: a = b = 3.4
In[23]: id(a)
Out[23]: 140293508599056
In[24]: id(b)
Out[24]: 140293508599056
In[25]: b = 5.8
In[26]: id(b)
Out[26]: 140293508598928
In[27]: id(a)
Out[27]: 140293508599056
none of the objects for 5, 6, or 30 have names. They are all integer objects.
Not having variable names associated with them, we say that they are integer
literals.
In[31]: type(b)
Out[31]: int
14 Introduction to Python for Science and Engineering
Notice that after we wrote b = 6, its type changed from float to int. This fea-
ture of Python is called dynamical typing. A variable’s type can change on the
fly. That’s all we’ll say about dynamic typing for now, but we will return to this
topic.
In[35]: velocity
Out[35]: 57.6271186440678
Note, however, that word processing programs like Microsoft Word® are
not suitable for this purpose because they produce files that, in addition to the
visible text, contain all sorts of formatting code that is invisible to the user but
not the computer (or the Python interpreter). You must use a plain text editor.
Code: my_trip.py
1 """ Calculates time , electrical energy used , and cost of electricity
2 for a trip in an electric vehicle """
3 # Get inputs
4 distance = 180. # [ miles ]
5 mpk = 3.9 # [ miles /kilowatt -h] car mileage
6 speed = 60. # [ miles /h] average speed
7 cost_per_kWh = 0.22 # [$/kW -h] price of electricity
8
9 # Calculate outputs
10 time = distance / speed # [ hours ]
11 energy = distance / mpk # [kW -h]
12 cost = energy * cost_per_kWh # [$]
Save the file with the name my_trip.py in the directory PyScripts that you
created earlier (see Section 2.5.1.1). This stores your script (or program) on
your computer’s disk. More generally, the name of a Python file can be almost
Launching Python 17
anything consistent with the computer operating system as long the name ends
with the extension .py. The .py extension tells the computer this is a Python
program.
The code in the program is pretty straightforward: lines 4–7 set the values
of the inputs, while lines 10–12 calculate the desired information. All of the
variables are floats by virtue of the decimal point included in each assignment
statement. Notice that we included a blank line, line 8, between the input and
output blocks of code. This is not necessary, as the blank line serves no compu-
tational purpose. Rather, it indicates to the reader that the blocks do different
things, analogous to what paragraphs do in normal written text.
The text between the triple quotes at the beginning of the program is called
a “docstring” and is not executed when the script is run. Everything between
the triple quotes is part of the docstring, which can extend over multiple lines,
as it does here. It’s a good idea to include a docstring explaining what your
script does at the beginning of your file.
The hash (or number) symbol # is the “comment” character in Python;
anything on a line following # is ignored when the code is executed. A com-
ment in a Python script is a brief explanation or annotation added to help
people reading the program understand what the program is doing. Judicious
use of comments in your code will make it much easier to understand days,
weeks, or months after you write it. Use comments generously. For aesthetic
reasons, the comments on different lines have been aligned. This isn’t neces-
sary. The spaces needed to align the comments have no effect on the running
of the code.
Now you are ready to run the code. From a QtConsole, type
In[1]: run ~/ Documents / PyScripts / my_trip .py
When you run a script, Python executes the sequence of commands in the
order they appear. Afterward, you can see the values of the variables calculated
in the script by typing the name of the variable. IPython responds with the
value of that variable. For example:
In[2]: time
Out[2]: 3.0
In[3]: energy
Out[3]: 46.15384615384615
In[4]: cost
Out[4]: 10.153846153846153
Of course, you must remember that the time is in hours, and the cost is in U.S.
dollars.
You can change the number of digits IPython displays using the com-
mand %precision. To display two digits to the right of the decimal place, enter
%precision 2:
In[5]: % precision 2
Out[5]: ' %.2f'
In[6]: time
Out[6]: 3.00
In[7]: energy
Out[7]: 46.15
In[8]: cost
Out[8]: 10.15
the script will return the values of the variables time, gallons, and cost that
the script calculated. We will discuss the print function in much greater detail,
as well as other methods for data output, in Chapter 5.
Launching Python 19
NumPy is the standard Python package for scientific computing with Python.
It provides the all-important NumPy array data structure, which is
at the very heart of NumPy. It also provides tools for creating and
manipulating arrays, including indexing and sorting, as well as ba-
sic logical operations and element-by-element arithmetic operations
like addition, subtraction, multiplication, division, and exponentia-
tion. It includes the basic mathematical functions of trigonometry,
exponentials, and logarithms, as well as a vast collection of special
functions (Bessel functions, etc.), statistical functions, and random
number generators. It also includes many linear algebra routines that
overlap with those in SciPy, although the SciPy routines tend to be
more comprehensive. You can find more information about NumPy at
http://docs.scipy.org/doc/numpy/reference/index.html.
Matplotlib is the standard Python package for making two- and three-
dimensional plots. Matplotlib makes extensive use of NumPy arrays. All
of the plots in this book use this package. You can find more informa-
tion about Matplotlib at the website http://matplotlib.sourceforge.net/.
We will use these four modules extensively and, therefore, will provide in-
troductions to their capabilities as we develop Python. The links above provide
much more extensive information; you will certainly want to refer to them oc-
casionally.
After running this statement, you can access all the functions and data struc-
tures of NumPy. For example, you can now access NumPy’s sine function as
follows:
In[2]: numpy.sin (0.5)
Out[2]: 0.479425538604203
In this simple example, the sin function has one argument, here 0.5, and the
function returns the sine of that argument, which must be expressed in radi-
ans.
Note that we had to put the prefix numpy dot before the name of the actual
function name sin. This tells Python that the sin function is part of the NumPy
module that we just imported.
Another Python module called math also has a sine function. We can im-
port the math module just like we imported the NumPy module:
In[3]: import math
Exploring the Variety of Random
Documents with Different Content
panic that turned it without any warning into a fleeing, fighting,
struggling, terror-stricken mob. The people rushed in every direction,
knocking down everything in their track. Miss Beatty went down like
a log, but she was up again in a flash, and we flung ourselves
against a high iron railing guarding a shop window. Directly beside
us lay a soldier who had had his head cut open by the glass sign
against which he was thrown. Many others were injured.
Typical crowd on the Nevski Prospect during the Bolshevik
or Maximalist risings.
Fortunately the panic was shortlived. It lasted hardly five minutes, as
a matter of fact. All around the cry rose that nothing was the matter,
that the Cossacks were not coming. The Cossacks, once the terror of
the Russian people, in this upheaval have become the strongest
supporters of the government. Nothing could better demonstrate the
anti-government intention of the Bolsheviki than their present fear
and hatred of the Cossacks. So the “Tavarishi” took up their battered
banners and resumed their march. No one ever found out what
started the panic. Some said that a shot was fired from a window on
one of the banners. Others said that the shot was merely a tire
blowing out. Some were certain that they heard a cry of “Cossacks,”
and some cynics suggested that the pick-pockets, a numerous and
enterprising class just now, started the panic in the interests of
business. This was the only disturbance I witnessed. The
newspapers reported two more in the course of the day. A young girl
watching the procession from the sidewalk suddenly decided to
commit suicide, and the shot she sent through her heart precipitated
another panic. Still a third one occurred when two men got into a
fight and one of them drew a knife.
The instant flight of the crowds and especially of the soldiers must
have given Kerensky hope that the giant could be got back into the
bottle, especially since on that very day, June 18, Russian style, the
army on one of the fronts advanced and fought a victorious
engagement. The town went mad with joy over that victory,
showing, I think, that the heart of the Russian people is still
intensely loyal to the allies, and deadly sick of the fantastic program
of the extreme socialists. Crowds surged up and down the street
bearing banners, flags, pictures of Kerensky. They thronged before
the Marie Palace, where members of the government, officers,
soldiers, sailors made long and rapturous speeches, full of
patriotism. They sang, they shouted, all day and nearly all night.
When they were not shouting “Long live Kerensky!” they were saying
“This is the last of the Lenineites.” But it wasn’t. The Bolsheviki
simply retired to their dancer’s palace, their Viborg retreats and their
Kronstadt stronghold, and made another plan.
On Monday night, July 2, or in our calendar July 15, broke out what
is known as the July revolution, the last bloody demonstration of the
Bolsheviki. I had been absent from town for two weeks and returned
to Petrograd early in the morning after the demonstration began. I
stepped out of the Nicholai station and looked around for a droshky.
Not one was in sight. No street cars were running. The town looked
deserted. Silence reigned, a queer, sinister kind of a silence. “What
in the world has happened?” I asked myself. A droshky appeared
and I hailed it. When the izvostchik mentioned his price for driving
me to my hotel I gasped, but I was two miles from home and there
were no trams. So I accepted and we made the journey. Few people
were abroad, and when I reached the hotel I found the entrance
blocked with soldiers. The man behind the desk looked aghast to see
me walk in, and he hastened to tell me that the Bolsheviki were
making trouble again and all citizens had been requested to stay
indoors until it was over.
I stayed indoors long enough to bathe and change, and then, as
everything seemed quiet, I went out. Confidence was returning and
the streets looked almost normal again. I walked down the Morskaia,
finding the main telephone exchange so closely guarded that no one
was even allowed to walk on the sidewalk below it. That telephone
exchange had been fiercely attacked during the February revolution,
and it was one of the most hotly disputed strategic positions in the
capital. Later I am going to tell something of the part played in the
revolution by the loyal telephone girls of Petrograd. A big armored
car was plainly to be seen in the courtyard of the building, and many
soldiers were there alert and ready. I stopped in at the big bookshop
where English newspapers (a month old) were to be purchased, and
bought one. The Journal de Petrograd, the French morning paper, I
found had not been issued that day. Then I strolled down the
Nevski. I had not gone far when I heard rifle shooting and then the
sound, not to be mistaken, of machine gun fire. People turned in
their tracks and bolted for the side streets. I bolted too, and made a
record dash for the Hotel d’Europe. The firing went on for about an
hour, and when I ventured out again it was to see huge gray motor
trucks laden with armed men, rushing up and down the streets,
guns bristling from all sides and machine guns fore and aft.
What had happened was this. The “Red Guard,” an armed band of
workmen allied with the Bolsheviki, together with all the extremists
who could be rallied by Lenine, and these included some very young
boys, had been given arms and told to “go out in the streets.” This is
a phrase that usually means go out and kill everything in sight. In
this case the men were assured that the Kronstadt regiments would
join them, that cruisers would come up the river and the whole
government would be delivered into the hands of the Bolsheviki. The
Kronstadt men did come in sufficient numbers to surround and hold
for two days the Tauride Palace, where the Duma meets and the
provisional government had its headquarters. The only reason why
the bloodshed was not greater was that the soldiers in the various
garrisons around the city refused to come out and fight. The sane
members of the Soviet had begged them to remain in their casernes,
and they obeyed. All day Tuesday and Wednesday the armed motor
cars of the Bolsheviki dashed from barrack to barrack daring the
soldiers to come out, and whenever they found a group of soldiers
to fire on, they fired. Most of these loyal soldiers are Cossacks, and
they are hated by the Bolsheviki.
Tuesday night there was some real fighting, for the Cossacks went to
the Tauride Palace and freed the besieged ministers at the cost of
the lives of a dozen or more men. Then the Cossacks started out to
capture the Bolshevik armored cars. When they first went out it was
with rifles only, which are mere toy pistols against machine guns.
After one little skirmish I counted seventeen dead Cossack horses,
and there were more farther down the street. As soon as the
Cossacks were given proper arms they captured the armored trucks
without much trouble. The Bolsheviki threw away their guns and fled
like rabbits for their holes. Nevertheless a condition of warfare was
maintained for the better part of a week, and the final burst of
Bolshevik activity gave Petrograd, already sick of bloodshed, one
more night of terror. That night I shall not soon forget.
The day had been quiet and we thought the trouble was over. I went
to bed at half-past ten and was in my first sleep when a fusilade
broke out, as it seemed, almost under my window. I sat up in bed,
and within a few minutes, the machine guns had begun their infernal
noise, like rattlesnakes in the prairie grass. I flung on a dressing
gown and ran down the hall to a friend’s room. She dressed quickly
and we went down stairs to the room of Mrs. Emmeline Pankhurst,
the English suffragette, which gave a better view of the square than
our own. There until nearly morning we sat without any lights, of
course, listening to repeated bursts of firing, and the wicked put-put-
put-put of the machine guns, watching from behind window
draperies, the brilliant headlights of armored motors rushing into
action, hearing the quick feet of men and horses hastening from
their barracks. We did not go out. All a correspondent can do in the
midst of a fight is to lie down on the ground and make himself as
flat as possible, unless he can get into a shop where he hides under
a table or a bench. That never seemed worth while to me, and I
have no tales to tell of prowess under fire.
I listened to that night battle from the safety of the hotel, going the
next day to see the damage done by the guns. A contingent of
mutinous soldiers and sailors from Kronstadt, which had been
expected for several days by the Lenineites, had come up late, still
spoiling for a fight; had planted guns on the street in front of the
Bourse and at the head of the Palace Bridge across the Neva, and
simply mowed down as many people as were abroad at the hour.
Nobody knows, except the authorities, how many were killed, but
when we awoke the next day we discovered that, for a time at least,
the power of the Bolsheviki had been broken. The next day the
mutinous regiments were disbanded in disgrace. Petrograd was put
under martial law, the streets were guarded with armored cars,
thousands of Cossacks were brought in to police the place, and
orders for the arrest of Lenine and his lieutenants were issued. But it
was openly boasted by the Bolsheviki that the government was
afraid to touch Lenine, and certain it is that he escaped into Sweden,
and possibly from there into Germany.
I should not like to believe that the government actually connived at
his escape, since there was always the menace of his return, and the
absolute certainty that he would remain an outsider directing force
in the Bolshevik campaign. It is more probable that in the confusion
of those days of fighting he was smuggled down the Neva in a small
yacht or motor boat to the fortress of Kronstadt, and from there was
conveyed across the mine strewn Baltic into Sweden. Rumor had it
that he had been seen well on his way to Germany, but it is more
likely that his employers kept him nearer the scene of his activities.
He was guilty of more successful intrigue, more murder and violent
death than most of the Kaiser’s faithful, and deserves an extra size
iron cross, if there is such a thing. In spite of all that he has done he
has thousands of adherents still in Russia, people who believe that
he is “sincere but misguided,” to use an overworked phrase. The rest
of the fighting mob were driven from their palace, which they had
previously looted and robbed of about twenty thousand dollars’
worth of costly furniture, china, silver and art objects. They were
hunted out of their rifle factory, and finally surrendered to the
government after they had captured, but failed to hold the fortress
of Peter and Paul. They surrendered but were they arrested and
punished? Not a bit of it. They were allowed to go scot free, only
being required to give up their arms. The government existed only at
the will of the mob, and the mob would not tolerate the arrest of
“Tavarishi.”
CHAPTER IV
AN HOUR OF HOPE