NumPy 3rd Edition Build efficient high speed programs using the high performance NumPy mathematical library Ivan Idris - Read the ebook online or download it to own the complete version
NumPy 3rd Edition Build efficient high speed programs using the high performance NumPy mathematical library Ivan Idris - Read the ebook online or download it to own the complete version
https://ebookfinal.com/download/numpy-cookbook-python-2nd-edition-
ivan-idris/
https://ebookfinal.com/download/super-high-strength-high-performance-
concrete-1st-edition-pu-xincheng-author/
https://ebookfinal.com/download/high-performance-mysql-3rd-edition-
optimization-backups-and-replication-baron-schwartz/
High Performance Android Apps Improve Ratings with Speed
Optimizations and Testing 1 (Early Release) Edition Doug
Sillars
https://ebookfinal.com/download/high-performance-android-apps-improve-
ratings-with-speed-optimizations-and-testing-1-early-release-edition-
doug-sillars/
https://ebookfinal.com/download/high-speed-vlsi-interconnections-2nd-
ed-edition-ashok-k-goel/
https://ebookfinal.com/download/r-high-performance-programming-1st-
edition-lim/
https://ebookfinal.com/download/postgresql-9-0-high-performance-
gregory-smith/
https://ebookfinal.com/download/nginx-cookbook-advanced-recipes-for-
high-performance-load-balancing-3rd-edition-derek-dejonghe/
NumPy 3rd Edition Build efficient high speed programs
using the high performance NumPy mathematical library
Ivan Idris Digital Instant Download
Author(s): Ivan Idris
ISBN(s): 9781785281969, 1785281968
File Details: PDF, 22.11 MB
Year: 2015
Language: english
www.it-ebooks.info
NumPy Beginner's Guide
Third Edition
Ivan Idris
BIRMINGHAM - MUMBAI
www.it-ebooks.info
NumPy Beginner's Guide
Third Edition
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.
ISBN 978-1-78528-196-9
www.packtpub.com
www.it-ebooks.info
Credits
Reviewers Proofreader
Alexandre Devert Safis Editing
Davide Fiacconi
Ardo Illaste Indexer
Rekha Nair
Commissioning Editor
Amarabha Banerjee Graphics
Sheetal Aute
Cover Work
Content Development Editor
Aparna Bhagat
Neeshma Ramakrishnan
Technical Editor
Rupali R. Shrawane
Copy Editors
Charlotte Carneiro
Vikrant Phadke
Sameen Siddiqui
www.it-ebooks.info
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.
www.it-ebooks.info
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.it-ebooks.info
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
[email protected] 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
www.it-ebooks.info
www.it-ebooks.info
www.it-ebooks.info
I dedicate this book to my aunt Lies who recently passed away. Rest in peace.
www.it-ebooks.info
www.it-ebooks.info
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]
www.it-ebooks.info
Table of Contents
[ ii ]
www.it-ebooks.info
Table of Contents
[ iii ]
www.it-ebooks.info
Table of Contents
[ iv ]
www.it-ebooks.info
Table of Contents
[v]
www.it-ebooks.info
Table of Contents
[ vi ]
www.it-ebooks.info
Table of Contents
[ vii ]
www.it-ebooks.info
Table of Contents
[ viii ]
www.it-ebooks.info
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.
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.
www.it-ebooks.info
Discovering Diverse Content Through
Random Scribd Documents
“I assure you, mother-in-law, that I had no intention——”
“That will do. I accept your excuses. We now come to a more
delicate matter, to—but, of course, you must understand me.”
“I confess that I do not at all.”
“Listen, son-in-law. Some newly married young men, on their
wedding-night, when the ball is at its gayest, take the liberty of
carrying off their wives, and disappearing with them about twelve
o’clock.”
“And you object to that?”
“Fie, sir, fie! If you were to be guilty of such a thing, I would make
your wife sue for a divorce the day after your marriage.”
“Be easy, then; I will not disappear. But when may I go away with
my wife?”
“I shall take my daughter with me, and arrange an opportune time
when the decencies of the situation may be observed.”
“And who will take me?”
“You will go alone, but you will not go, understand me well, until
there isn’t a cat left at the ball.”
“I shall be getting to bed very late, then. Some of the people will
want square dances and country dances, and——”
“You will get to bed soon enough, son-in-law.”
“But why all this, mother-in-law?”
“That will do, M. Tamponnet! It is not becoming that this
conversation be prolonged.”
Théophile Gautier, poet, artist and novelist was identified with the
romantic movement in French literature.
A charming art of description was his, as may be seen in the story
of the Lap Dog.
FANFRELUCHE
AN EVENING RECEPTION
Once upon a time there was a wicked king, who made his people
very unhappy. Everybody detested him, and those whom he had put
in prison and beheaded would have liked to whip him. But how? He
was the strongest, he was the master, he did not have to give
account to any one, and when he was told his subjects were not
content, he replied:
“Well, what of it? I don’t care a rap!” Which was an ugly answer.
As he continued to act like a king, and as every day he became a
little more wicked than the day before, this set a certain little flea to
thinking over the matter. It was a little bit of a flea, who was of no
consequence at all, but full of good sentiments. This is not the nature
of fleas in general; but this one had been very well brought up; it bit
people with moderation, and only when it was very hungry.
“What if I were to bring the king to reason?” it said to itself. “It is
not without danger. But no matter—I will try.”
That night the wicked king, after having done all sorts of naughty
things during the day, was calmly going to sleep when he felt what
seemed to be the prick of a pin.
“Bite!”
He growled, and turned over on the other side.
“Bite! Bite! Bite!”
“Who is it that bites me so?” cried the king in a terrible voice.
“It is I,” replied a very little voice.
“You? Who are you?”
“A little flea who wishes to correct you.”
“A flea? Just you wait! Just you wait, and you shall see!”
And the king sprang from his bed, twisted his coverings, and
shook the sheets, all of which was quite useless, for the good flea
had hidden itself in the royal beard.
“Ah,” said the king, “it has gone now, and I shall be able to get a
sound sleep.”
But scarcely had he laid his head on the pillow, when—
“Bite!”
“How? What? Again?”
“Bite! Bite!”
“You dare to return, you abominable little flea? Think for a moment
what you are doing! You are no bigger than a grain of sand, and you
dare to bite one of the greatest kings on earth!”
“Well, what of it? I don’t care a rap!” answered the flea in the very
words of the king.
“Ah, if I only had you!”
“Yes, but you haven’t got me!”
The wicked king did not sleep all that night, and he arose the next
morning in a killing ill humor. He resolved to destroy his enemy. By
his orders, they cleaned the palace from top to bottom, and
particularly his bedroom; his bed was made by ten old women very
skilful in the art of catching fleas. But they caught nothing, for the
good flea had hidden itself under the collar of the king’s coat.
That night, this frightful tyrant, who was dying for want of sleep,
lay back on both his ears, though this is said to be very difficult. But
he wished to sleep double, and he knew no better way. I wish you
may find a better. Scarcely had he put out his light, when he felt the
flea on his neck.
“Bite! Bite!”
“Ah, zounds! What is this?”
“It is I—the flea of yesterday.”
“But what do you want, you rascal—you tiny pest?”
“I wish you to obey me, and to make your people happy.”
“Ho, there, my soldiers, my captain of the guard, my ministers, my
generals! Everybody! The whole lot of you!”
The whole lot of them came in. The king was in a rage, which
made everybody tremble. He found fault with all the servants of the
palace. Everybody was in consternation. During this time the flea,
quite calm, kept itself hid in the king’s nightcap.
The guards were doubled; laws and decrees were made;
ordinances were published against all fleas; there were processions
and public prayers to ask of Heaven the extermination of the flea,
and sound sleep for the king. It was all of no avail. The wretched
king could not lie down, even on the grass, without being attacked by
his obstinate enemy, the good flea, who did not let him sleep a single
minute.
“Bite! Bite!”
It would take too long to tell the many hard knocks the king gave
himself in trying to crush the flea; he was covered with bruises and
contusions. As he could not sleep, he wandered about like an
uneasy spirit. He grew thinner. He would certainly have died if, at
last, he had not made up his mind to obey the good flea.
“I surrender,” he said at last, when it began to bite him again. “I
ask for quarter. I will do what you wish.”
“So much the better. On that condition only shall you sleep,”
replied the flea.
“Thank you. What must I do?”
“Make your people happy!”
“I have never learned how. I do not know how——”
“Nothing more easy: you have only to go away.”
“Taking my treasures with me?”
“Without taking anything.”
“But I shall die if I have no money,” said the king.
“Well, what of it? I don’t care!” replied the flea.
But the flea was not hard-hearted, and it let the king fill his
pockets with money before he went away. And the people were able
to be very happy by setting up a republic.
WILLIAM TELL
The party of travelers now came to the Lake of Lucerne, with its
dark waters overshadowed by high and menacing mountains. To
their right they saw that Ruetli meadow where Melchthal, Fuerst, and
Stauffacher had sworn the oath to deliver their country.
Tartarin, deeply moved, took off his cap, and even threw it into the
air three times to render homage to the shades of the departed
heroes. Some of the tourists mistook this for a salutation, and bowed
in return. At last they reached Tell’s Chapel. This chapel is situated
at the edge of the lake, on the very rock upon which, during the
storm, William Tell jumped from Gessler’s boat. And it was a
delicious emotion to Tartarin, while he followed the travelers along
the lake, to tread this historic ground, to recall and revive the various
scenes of this great drama, which he knew as well as his own
biography.
For William Tell had always been his ideal man. When at
Bézuquet’s pharmacy the game of Preferences was being played,
and each one wrote on his slip of paper the name of the poet, the
tree, the odor, the hero, and the woman that he preferred to all
others of their kind, one slip invariably bore this inscription:
“Favorite tree?—The baobab.
“Favorite odor?—Gunpowder.
“Favorite author?—Fenimore Cooper.
“Who would you like to have been?—William Tell.”
And then everybody would exclaim, “That’s Tartarin!”
Imagine, then, how happy he was, and how his heart beat when
he stood before the chapel commemorative of the gratitude of a
whole nation. It seemed to him as if William Tell must come in person
to open the door, still dripping from the waters of the lake, and
holding in his hand his bolts and crossbow.
“Don’t come in here. I’m working. This is not the day on which
tourists are allowed,” sounded a strong voice from the interior,
reechoing against the walls.
“M. Astier-Réhu, of the French Academy!”
“Herr Professor Doctor Schwanthaler!”
“Tartarin of Tarascon!”
The painter, who was standing on a scaffolding within, stretched
out half of his body clad in his working-blouse, and holding his
palette in his hand.
“My pupil will come down and open the door for you, gentlemen,”
he said in a respectful tone.
“I was sure of it; of course,” said Tartarin to himself, “I have only to
mention my name.”
For all that, he had the good taste to fall into line and modestly
enter the chapel behind the others.
The painter, a splendid fellow, with a magnificent golden head of
an artist of the Renaissance, received his visitors on the wooden
staircase which led to the temporary scaffolding from which the
mural paintings were being done. All the frescos, representing
scenes from Tell’s life, were complete, except the one in which the
scene of the apple at Altorf was to be shown. Upon that the painter
was now working....
“I find it all very characteristically done,” said the great Astier-
Réhu.
And Schwanthaler, folding his arms, recited two of Schiller’s
verses, half of which was lost in his beard. Then the ladies delivered
their opinions, and for some minutes one would have thought oneself
in a confectioner’s shop. “Beautiful!” they cried. “Lovely! Exquisite!
Delicious!”
Suddenly came a voice, tearing the silence like a trumpet’s blare:
“Badly shouldered, that blunderbuss, I tell you! He never held it in
that way!”
Imagine the stupefaction of the painter when this tourist, stick in
hand and bundle on his back, undertook to demonstrate to him as
clearly as that two and two are four, that the position of Tell in the
picture was incorrect.
“And I understand these matters, I would have you know!”
“And who are you?”
“Who am I?” said our Tarasconian hero, deeply astonished. And
so it was not at his name that the door had opened. Drawing himself
up, he answered, “Ask the panthers of Zaccar, or the lions of Atlas,
and perhaps they will answer you.”
Every one drew away from Tartarin in fright and consternation.
“But then,” asked the painter, “in what respect is Tell’s position
incorrect?”
“Look at me!”
Falling back with a double step that made the planks creak,
Tartarin, using his cane to represent the “blunderbuss,” threw himself
into position.
“Superb! He is right! Don’t move!” cried the painter. Then to his
pupil:
“Quick, bring me paper and charcoal!”
GERMAN HUMOR
Christian F. Gellert, a German poet of the early Eighteenth
century, was also a lecturer and professor of philosophy.
His literary fame rests upon his sacred songs and his fables. One
of the latter we quote.
THE PATIENT CURED
A man long plagued with aches in joint and limb
Did all his neighbors recommended him,
But, despite that, could nowise gain
Deliverance from his pain.
An ancient dame, to whom he told his case,
Cut an oracular grimace,
And thus announced a magic remedy:
“You must,” said she,
Mysteriously hissing in his ear,
And calling him “My dear,”
“Sit on a good man’s grave at early light,
And with the dew fresh-fallen over night
Thrice bathe your hands, your knee-joints thrice:
’Twill cure you in a trice.
Remember her who gave you this advice.”
THE RAVEN
The raven remarked that the eagle sat thirty days upon her eggs.
“That, undoubtedly,” said she, “is the reason why the young of the
eagle are so all-seeing and strong. Good! I will do the same.”
And, since then, the raven actually sits thirty days upon her eggs;
but, as yet, she has hatched nothing but miserable ravens.—Fables.
A man had an excellent bow of ebony, with which he shot very far
and very sure, and which he valued at a great price. But once, after
considering it attentively, he said:
“A little too rude still! Your only ornament is your polish. It is a pity!
However, that can be remedied,” thought he. “I will go and let a first-
rate artist carve something on the bow.”
He went, and the artist carved an entire hunting-scene upon the
bow. And what more fitting for a bow than a hunting-scene?
The man was delighted. “You deserve this embellishment, my
beloved bow.” So saying, he wished to try it.
He drew the string. The bow broke!—Fables.
EPIGRAMS
From the grave where dead Gripeall, the miser, reposes,
What a villainous odor invades all our noses!
It can’t be his body alone—in the hole
They have certainly buried the usurer’s soul.
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookfinal.com