Web-Books
im Austria-Forum
Austria-Forum
Web-Books
Informatik
Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Band Second Edition
Seite - 56 -
  • Benutzer
  • Version
    • Vollversion
    • Textversion
  • Sprache
    • Deutsch
    • English - Englisch

Seite - 56 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Band Second Edition

Bild der Seite - 56 -

Bild der Seite - 56 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Band Second Edition

Text der Seite - 56 -

56 2 AFewMoreSteps One more handyfunction fromnumpydeservesmention. If you have an array15 with numbers, you can shuffle those numbers in a randomized way with the shuffle function, In [1]: import numpy as np In [2]: a = np.array([1, 2, 3, 4]) In [3]: np.random.shuffle(a) In [4]: a Out[4]: array([1, 3, 4, 2]) Note that alsonumpy allows the seed to be set. For example, setting the seed to 10 (asabove),couldbedoneby np.random.seed(10) The fact that a module by the name random is found both in the standard Python libraryrandomand innumpy, calls for some alertness. With proper import statements (discussed in Sect.1.4.1),however, there shouldbenoproblem. For more details about thenumpy functions for pseudo-randomnumbers, check out the documentation(https://docs.scipy.org/doc/). 2.5 Exercises Exercise2.1: InteractiveComputingofVolume Redothe task inExercise1.2byusingPythoninteractively.Comparewithwhatyou gotpreviously fromthewrittenprogram. Exercise2.2: InteractiveComputingofCircumferenceand Area Redothe task inExercise1.3byusingPythoninteractively.Comparewithwhatyou gotpreviously fromthewrittenprogram. Exercise2.3:UpdateVariableatCommandPrompt InvokePython interactivelyandperformthe followingsteps. 1. Initializeavariablex to2. 2. Add3 tox. Printout the result. 3. Printout the resultofx + 1*2and(x+1)*2. (Observehowparenthesesmakea difference). 4. Whatobject typedoesx refer to? Exercise2.4:Multiple StatementsonOneLine a) Theoutputproducedby the followingtwo lineshasbeenremoved.Canyoutell, fromjust reading the input,what theoutputwas in eachcase? 15 Instead of an array, we can also use a list, see Sect.5.1.
zurück zum  Buch Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Band Second Edition"
Programming for Computations – Python A Gentle Introduction to Numerical Simulations with Python 3.6, Band Second Edition
Titel
Programming for Computations – Python
Untertitel
A Gentle Introduction to Numerical Simulations with Python 3.6
Band
Second Edition
Autoren
Svein Linge
Hans Petter Langtangen
Verlag
Springer Open
Datum
2020
Sprache
englisch
Lizenz
CC BY 4.0
ISBN
978-3-319-32428-9
Abmessungen
17.8 x 25.4 cm
Seiten
356
Schlagwörter
Programmiersprache, Informatik, programming language, functional, imperative, object-oriented, reflective
Kategorie
Informatik
Web-Books
Bibliothek
Datenschutz
Impressum
Austria-Forum
Austria-Forum
Web-Books
Programming for Computations – Python