An Introduction to Python Programming for Scientists and Engineers Johnny Wei-Bing Lin instant download
An Introduction to Python Programming for Scientists and Engineers Johnny Wei-Bing Lin instant download
https://ebookmeta.com/product/an-introduction-to-python-
programming-for-scientists-and-engineers-johnny-wei-bing-lin/
https://ebookmeta.com/product/introduction-to-python-for-
engineers-and-scientists-open-source-solutions-for-numerical-
computation-1st-edition-sandeep-nagar/
https://ebookmeta.com/product/introduction-to-scilab-for-
engineers-and-scientists-1st-edition-sandeep-nagar/
https://ebookmeta.com/product/introduction-to-octave-for-
engineers-and-scientists-1st-edition-sandeep-nagar/
https://ebookmeta.com/product/serial-sabotage-1st-edition-
carolyn-keene/
Yard Birds The Lives and Times of America s Urban
Chickens First Edition Philip Levy
https://ebookmeta.com/product/yard-birds-the-lives-and-times-of-
america-s-urban-chickens-first-edition-philip-levy/
https://ebookmeta.com/product/swaimans-pediatric-neurology-
principles-and-practice-6th-edition-kenneth-f-swaiman/
https://ebookmeta.com/product/handbook-of-pediatric-epilepsy-
case-studies-2nd-edition-maria-augusta-montenegro/
https://ebookmeta.com/product/electrophysiological-recording-
techniques-2nd-edition-robert-p-vertes-editor-timothy-allen-
editor/
https://ebookmeta.com/product/prince-musical-icon-1st-edition-
stephanie-watson/
Joseph Portraits Through the Ages 1st Edition Alan T.
Levenson
https://ebookmeta.com/product/joseph-portraits-through-the-
ages-1st-edition-alan-t-levenson/
An Introduction to Python Programming for
Scientists and Engineers
Python is one of the most popular programming languages, widely used for data analysis
and modelling, and is fast becoming the leading choice for scientists and engineers. Unlike
other textbooks introducing Python, typically organised by language syntax, this book uses
many examples from across Biology, Chemistry, Physics, Earth science, and Engineering to
teach and motivate students in science and engineering. The text is organised by the tasks
and workflows students undertake day-to-day, helping them see the connections between
programming tools and their disciplines. The pace of study is carefully developed for complete
beginners, and a spiral pedagogy is used so concepts are introduced across multiple chapters,
allowing readers to engage with topics more than once. “Try This!” exercises and online
Jupyter notebooks encourage students to test their new knowledge, and further develop their
programming skills. Online solutions are available for instructors, alongside discipline-specific
homework problems across the sciences and engineering.
Hannah Aizenman is a Ph.D. candidate in Computer Science at The Graduate Center, City
University of New York. She studies visualization and is a core developer of the Python
library Matplotlib.
Erin Manette Cartas Espinel graduated with a Ph.D. in physics from the University of
California, Irvine. After more than 10 years at the University of Washington Bothell, she
is now a software development engineer.
Joanne Liu received her Ph.D. in Bioinformatics and Systems Biology from the University of
California San Diego.
“This book provides an excellent introduction to the Python language especially targeted at those
interested in carrying out calculations in the physical sciences. I especially like the strong coverage of
graphics and of good coding practice.”
Raymond Pierrehumbert, University of Oxford
“An excellent introduction to Python for scientists and engineers. Much more than teaching you how to
program with Python, it teaches you how to do science with Python.”
Eric Shaffer, University of Illinois at Urbana-Champaign
“Python has achieved an essential role in many disciplines within science, engineering, and beyond.
Students and professionals are expected to be fluent in it, and (as I see in my daily job of helping users of a
high-performance computing facility) they often struggle to reach that fluency. The authors have succeeded
in the daunting task of writing a single book to help people reach a very advanced level of fluency, starting
very gently and assuming no background. Unlike other books on the subject, An Introduction to Python
Programming for Scientists and Engineers focuses on teaching for the intended end goal of scientists and
engineers – investigating their scientific problems – not writing software for its own sake. I am looking
forward to working with the generation who will learn how to program in Python using this book!”
Davide Del Vento, NCAR Computational & Information Services Laboratory
“An Introduction to Python Programming for Scientists and Engineers introduces programming in Python
using evidence-based approaches to active learning. The exercises help both students and instructors
identify misconceptions in programming, allowing students to build a strong foundation in Python
programming. The book streamlines content such that there is a focus on mastering immediately useful
concepts, normalizing errors, and demonstrating recovery.”
Kari L. Jordan, Executive Director, The Carpentries
An Introduction to Python
Programming for Scientists
and Engineers
Hannah Aizenman
City College of New York
Kim Gunnerson
University of Washington Bothell
Joanne Liu
Novozymes A/S
University Printing House, Cambridge CB2 8BS, United Kingdom
www.cambridge.org
Information on this title: www.cambridge.org/highereducation/isbn/9781108701129
DOI: 10.1017/9781108571531
A catalogue record for this publication is available from the British Library.
v
vi Contents
20 Recursion 633
Glossary 719
Acronyms and Abbreviations 726
Bibliography 727
Index 729
Detailed Contents
vii
viii Detailed Contents
20 Recursion 633
20.1 Example of Recursion 633
20.2 Python Programming Essentials 635
20.2.1 Using the walk Generator 635
20.2.2 Recursion and Writing Recursive Code 637
20.2.3 More Applications of Recursion 642
20.3 Try This! 645
20.4 More Discipline-Specific Practice 649
20.5 Chapter Review 649
20.5.1 Self-Test Questions 649
20.5.2 Chapter Summary 650
20.5.3 Self-Test Answers 651
Translator: H. Parker
Language: English
LONDON
LUZAC & CO
Publishers to the India Office
1910
[All Rights Reserved]
Butler & Tanner The Selwood Printing Works Frome and London
CONTENTS
PAGE
Introduction 1
PART I.
NO.
1 The Making of the Great Earth 47
2 The Sun, the Moon, and Great Paddy 52
3 The Story of Senasurā 54
4 The Glass Princess 57
5 The Frog Prince 67
6 The Millet Trader 72
7 The Turtle Dove 79
8 The Prince and the Princess 93
9 Tamarind Ṭikkā 100
10 Mātalangē Loku-Appu 108
11 The White Turtle 113
12 The Black Storks’ Girl 120
13 The Golden Kaekiri Fruit 129
14 The Four Deaf Persons 134
15 The Prince and the Yakā 137
16 How a Yakā and a Man fought 146
17 Concerning a Man and Two Yakās 148
18 The Three Questions 150
19 The Faithless Princess 157
20 The Prince who did not go to School 160
21 Nagul-Munnā 169
22 The Kulē-bakā Flowers 173
23 Kurulu-gama Appu, the Soothsayer 179
24 How a Prince was chased by a Yaksanī 186
25 The Wicked King 191
26 The Kitul Seeds 197
27 The Speaking Horse 199
28 The Female Quail 201
29 The Pied Robin 206
30 The Jackal and the Hare 209
31 The Leopard and the Mouse-deer 213
32 The Crocodile’s Wedding 216
33 The Gamarāla’s Cakes 219
34 The Kinnarā and the Parrots 224
35 How a Jackal settled a Lawsuit 228
36 The Jackal and the Turtle 234
37 The Lion and the Turtle 241
PART II.
Index 383
INTRODUCTION
When the forest and jungle of north-central or north-western Ceylon
is viewed from the upper part of a hill of considerable height, it has
the appearance of a dark green sea, across which, if there be any
wind, waves closely resembling those of the ocean roll along in
parallel lines as the swaying tree tops bend under the gusts of the
breeze. As clouds pass between it and the sun their shadows of
darker green follow each other over this seemingly illimitable ocean.
The undulations of the ground are lost; all appears to be at one
general level, except that here and there a little island is visible
where a low rocky mound succeeds in raising its head above the
verdant waves.
We leave the dusty main roads, and follow a winding village path,
never straight for a hundred yards except by accident—not such a
path as was constantly encountered thirty or more years ago, on
which the overhanging thorny bushes often made it necessary to
bend low or run the risk of having one’s clothes torn, but a track
flanked with grass, having the bushes completely cleared away for a
width of twelve feet.
Near the middle of the clearing, where two young trees grow in
proximity, two thin posts have been fixed in the ground, and
between these four supports a floor of sticks has been constructed
at a height of ten or twelve feet above the ground, reached by a
rough stick ladder with rungs two feet apart, and having a thatched
roof overhead, and a flimsy wall of sticks, interwoven with leafy
twigs or grass on the windward side. A thin floor of earth, watered
and beaten until it became hard, permits a small fire of sticks to be
made in the shelter if the nocturnal air be chilly. In this solitary
watch-hut a man, or sometimes two, sit or lie nightly, in order to
drive away intruding animals that may successfully evade or break
through the protecting fence, and feed on the crop.
Along the path through the chēna jungle there are not many signs of
life. A Monitor Lizard or “Iguana,” about four feet long, which we
frighten as it was licking up ants and other insects on the roadside
with its extensile thin tongue, scurries off quickly, and disappears
down a hole in the side of an anthill. Over the jungle come the slow
monotonous calls, “Tok, tok, tok, tok,” of a small Barbet, perched on
the topmost twig of one of the higher trees, jerking its body to the
right and left as it repeats its single note. A Woodpecker crosses the
path with a screaming cry, three times repeated, and a few other
birds may appear at intervals, but otherwise there is not much to
break the sameness.
Then, if one be lucky, comes a tract of the original forest that has
escaped the chēna clearer’s destructive bill-hook and fires, in which
is immediately experienced the welcome relief afforded by the
delightful cool shade cast by the forest trees of many species which
stretch high above the lower bushes. This is the home of the
Elephant, traces of which are observed in the wide footprints and an
occasional broken-down sapling or fractured branch. A slightly
leaning tree on the side of the path has tempted one to rub his back
on it, and lower down are the scratches left by a Leopard’s claws, as
he scraped them on it like a cat.
As we pass along the leaf-strewn way, the loud hoarse cry, “Hō, hō,”
of the large grey Monkeys (Semnopithecus priamus) whom we
startle, resounds through the trees. They cease to feed on the
succulent young leaves, and shake the rustling branches in their bold
leaps among the higher ones. This is soon followed by a sudden
stillness as they mysteriously conceal themselves, vanishing as
though by magic among the denser foliage.
Bird calls unfamiliar to a stranger are heard, especially the short cry
of two notes, rather than the crow, of the Jungle-cock—the wild
game-fowl of Ceylon,—the sheep-like bleats of the Lesser Hornbill,
sometimes the rich notes of the Crested Drongo, or the often
reiterated whistle, “To meet ye´-ou,” of the Whistling Babbler. A
charming Ground Dove that was picking up seeds on the path, flies
off quickly down the path, and turns suddenly through the bushes. A
few white or brown or striped Butterflies, and sometimes the lovely,
large, dark velvety-green or steely blue Ornithoptera, flit about. A
few sharp notes, uttered as a small timid creature, little bigger than
a hare, darts off under the bushes, tell us that we have startled a
little Mouse-deer, Mīminnā. These fragile-looking animals always
stand on tiptoe, appearing exactly, as Mr. R. A. Sterndale expressed
it in his work, The Mammalia of India, “as if a puff of wind would
blow them away.” But as a rule, there is not much animal life
noticeable even in these forests, unless one can spare time to search
for it.
Another patch of the chēna jungle succeeds the forest, and then the
path reaches one end of the embankment of a village tank or
reservoir, a shallow sheet of water varying in size from two or three
acres to more than one hundred, but commonly from twenty to fifty
in area. The trim, earthen, grass-sloped embankment, nearly
straight, from an eighth of a mile to half a mile long, from nine to
sixteen feet high, and six feet wide on the top, rises a few feet
above the water level.
In its contrast with the parched and heated ground along which we
have come, the scene always appears strikingly beautiful. There are
few fairer spots on the earth than some of the village tanks when
they are nearly full of water. Here we may sit in the cool shelter of
an umbrageous tree, and contemplate nature in its most idyllic
aspect. The busy world, with its turmoil and stress, its noisy factories
and clanging machinery, its hurrying railway trains and motor-cars,
its crowded cities full of an artificial and unhealthy existence, has
disappeared, as though it had been merely a fantastic vision of the
night. Here all is peace: an uneventful calm that has survived the
changes of perhaps two thousand years, and that may be unaltered
in another two thousand. One may wonder if the fevered life of the
present western civilisation will last as long, or will have burnt itself
out, and been swept away like that of the dead civilisations that
preceded it.
A few black Cormorants and a white Egret or two may also be there,
resting on another part of the rock; and close to the water even one
or two little Black Tank Turtles, but not the edible White Tank Turtle
(Kiri-ibbā), which is much less common. On a stump in the water is
usually perched a Darter, a bird that can outswim its fishy prey, with
long snake-like neck, drying its expanded wings under the fiery
tropical rays. Its mate will be immersed in the water, in which it
swims with only its head and neck visible above the surface.
Near the upper margin of the tank wades, with long deliberate
strides, a lanky Great White Egret (Herodias alba), its neck
outstretched in advance, and head held ready for a rapid spear-like
thrust of its long tapering bill at any frog or small fish incautious
enough to remain within its fatal reach. Nearer the edge of the
shallowest water Lesser Egrets step more hurriedly in search of
frogs, and often chase them as they rush spluttering along its
surface.
Near the side of the tank are to be seen the upper parts of the dark
heads of buffaloes, of which the bodies are immersed, as they lazily
chew the cud. A White Egret is perched on one whose back appears
above the water. At intervals a head disappears quietly below the
surface, and the dense crowd of small flies that had settled on it is
driven to flight, only to return once more as soon as it rises again.
When such a shed is erected on the side of a path for public use, it
may have, but rarely, half walls four feet high; or the posts may be
tenoned into a rectangle of substantial squared logs that are halved
into each other at the angles, where they rest upon large stones, so
as to be clear of the ground, and thus partly protected from attacks
by white ants. The squared beams act as seats for the tired passer-
by.
When there is no suitable shed of this kind for the visitor, a hut,
usually one belonging to the village headman, is swept out and
temporarily given up to our use. If information of the coming visit
had been sent beforehand, the hut or shed would have been
provided with a ceiling made of lengths of white calico borrowed
from the family washerman, and perhaps the walls also would have
been hung with others, sometimes including such coloured ones as
he had washed for some of the villagers.
Near the end of the house, and within sight of the veranda, there
are one or two round corn stores, considerably wider at the top than
at the base, with conical thatched roofs. They rest upon cross sticks
placed upon four horizontal adzed logs, which are supported by four
small rough blocks of stone at the corners. Their walls are made of a
wicker frame hung from four or five durable posts set in the ground,
which are usually the heart wood of trees that are not eaten by
white ants. The upper part of the wicker frame is firmly tied to the
tops of these, and the whole wicker work is then thickly overlaid and
stiffened by successive coatings of mixed clay and sand, on which,
as on all the walls and floor of the dwelling house, there is placed a
thin surface wash of cow-dung.
The open ground along the front of the house is clean, and free
from grass and weeds, and is swept every morning. In this space,
called the miḍula, there is a stand of peeled sticks supported on thin
posts, and having a stick platform about four feet, or a little more, in
length and two feet in width, raised three feet from the ground, with
often another similar platform below it. On these are laid, after being
washed, the blackened earthenware cooking pots of the house, and
spoons made of segments of coconut shell with long wooden
handles, which are used with them.
In the little kitchen at the end of the house, with a lean-to roof, the
hearths or fire-places called lipa are formed of three round stones
fixed on the ground, about eight inches apart, on which are set the
cooking pots, over a fire of dry sticks. Sometimes a separate small
shed is built as a kitchen, but often the cooking is done inside the
single apartment of the house, at one end of it.
On the outer side of the village, near the embankment of the tank,
there are the large, rough-stemmed Tamarind trees that we noticed
as we came. A number of separate thin posts are fixed in the bare
ground below them, to which are tethered a few small Buffalo
calves, which will be joined by their mothers at dusk, after their bath
in the tank is finished.
On our return to the shed we see that our host’s wife has cooked his
evening meal of boiled rice and vegetable curry, with a bit of sun-
dried fish as a flavouring, these last being often made burning hot
with red chillies. She serves it in the raised veranda to him and a
relative who has come from a distant village, after giving them water
for rinsing out their mouths. Both sit or “squat” on their heels, and
convey the food to their mouths with their right hands, out of the
shallow, rather wide basins that act as plates. Where the supply of
such household articles runs short, leaf plates made of a piece of
plantain leaf, or two or three halmilla leaves pinned together, are
used. When they have finished the meal, and have rinsed their right
hands and drunk water—which is never taken while eating—and
have been served with a chew of betel leaf and its accompaniments,
the wife eats the remains of the meal alone, inside the house. If she
and her husband were alone they would take it together, the
husband being first served.
The men now sit on mats spread in the narrow veranda, where a
little oil lamp is perhaps hung, and the woman, after throwing out
the remains of the food for the dog, and washing the basins and
cooking utensils, and arranging them on their stand, joins the party,
and shares in the evening’s conversation. Sometimes, however, she
finds it necessary to pound some paddy until bed-time, in order to
remove the husk, in readiness for the meals of the following day; or
millet or rice may require grinding into flour in the stone quern.
If some intimate village friends were there, this would be the time
when, after discussing the events of the day, or making
arrangements for the morrow, a member of the party might finish
the evening’s chat by relating one of the familiar old stories of which
translations appear in this book.
In the end the woman retires, the visitor stretches himself on his
grass mat in the veranda, and the host extinguishes the lamp, if one
had been lit, and enters the single room of his house. On the next
night it will be his turn to occupy the watch-hut at the chena, where
his partner is sitting now.
All take care to lie, if possible, in an east and west direction, and on
no account with their heads to the south. This is the abode of Yama,
the god of death, while the north is the quarter inhabited by
demons. These directions are therefore exposed to evil influences
which might affect the sleeper, and perhaps cause such unlucky
omens as evil dreams.
The dog curls himself on the ground at the front of the house, the
cat wanders off to join some village cronies, and all is silent in the
village, except the rustling of the Coconut fronds overhead, the
monotonous call, “Wuk; chok-chŏ-tok,” uttered by a small owl in one
of the higher trees, and the more distant chorus of the frogs in the
adjoining rice field.
The earliest cry of the morning is the deep booming note, three or
four times repeated, of the large Ground Cuckoo (Centrococcyx
rufipennis), which is heard soon after dawn appears. Our host’s wife
is at work before daylight, scraping into shreds the kernel of a half
coconut, and preparing some milk-rice—rice boiled in milk made by
squeezing grated coconut in water until the latter assumes the
colour of milk.
By sun-rise, the Crows of the village are astir, and the Parrakeets,
commonly called “Parrots” in the East, which have been sleeping in
the coconut trees, fly away in parties in search of food.
Our host is about to leave his room after his night’s rest, when the
chirp of a little pale-coloured House Lizard on the wall causes him to
turn back suddenly, in order to avoid the evil influences against
which the wise Lizard had uttered its warning voice. He occupies
himself in the house for a short time longer, and then, at a luckier
moment, makes his appearance afresh, taking care to step over the
threshold with the right foot first.
A man or two, and a few boys, come from the adjoining houses to
watch our doings, from the open space in front of the house, or the
veranda; but all turn their faces away and ignore us from the
moment when we sit down to our “early tea,” and until it is finished.
This is done so as to avoid any risk of our food’s affecting us
injuriously, owing to a possible glance of the Evil Eye, which a
person may possess without being aware of the fact.
We notice a little copper tube slung on the right upper arm of our
host’s wife, by means of a yellow thread which passes through two
rings on its under side. In reply to our carefully worded inquiry
regarding it, he informs us that as she had been troubled with evil
dreams they had thought it advisable to get a friend of his, a
Vedarāla or doctor, who was acquainted with astrological and
magical lore, to supply her with a magical diagram and spell against
dreams, inscribed on a strip of dried palm leaf, which was rolled up
and placed in the tube. The thread, a triple one, was coloured with
saffron, and nine knots were made on it before it was tied on her
arm, a magical spell being repeated as each knot was made. Thanks
to this safeguard the dreams had ceased, but it was considered
advisable not to remove the thread and charm for a few weeks
longer.
Our host’s relative, having eaten some milk-rice, and taken a chew
of betel and areka-nut in his mouth, is about to return to his distant
village, and now leaves, saying only, “Well, I am going.” “It is good;
having gone come,” is the reply. The latter word must not be
omitted, or it might appear that his return in the future was not
desired.