<jupyter_start><jupyter_text>Python for scientific computing<NAME> > *Python is a programming language that lets you work more quickly and integrate your systems more effectively. You can learn to use Python and see almost immediate gains in productivity and lower maintenance costs* ([python.org](http://python.org/)).Python is also the name of the software with the most-widely used implementation of the language (maintained by the [Python Software Foundation](http://www.python.org/psf/)). This implementation is written mostly in the *C* programming language and it is nicknamed CPython. So, the following phrase, although with different meanings for the word *Python*, is correct: download Python *(the software)* to program in Python *(the language)* because Python *(both)* is great!   The origin of the name for the Python language in fact is not because of the big snake, the author of the Python language, <NAME>, named it after Monty Python, a famous British comedy group in the 70's. In turn, why Monty Python (the full name of the television series was *Monty Python's Flying Circus*) is less clear. Anyway, the Monty Python group was very interested in human movement science and research grant in the area! See this hilarious sketch:<jupyter_code>from IPython.display import YouTubeVideo
YouTubeVideo('9ZlBUglE6Hc', width=480, height=360, rel=0)<jupyter_output><empty_output><jupyter_text>Python characteristicsHere is a nice description about Python from its own [documentation](http://www.python.org/doc/essays/blurb/):   > *Python is an interpreted, object-oriented, high-level programming language with dynamic semantics. Its high-level built in data structures, combined with dynamic typing and dynamic binding, make it very attractive for Rapid Application Development, as well as for use as a scripting or glue language to connect existing components together. Python's simple, easy to learn syntax emphasizes readability and therefore reduces the cost of program maintenance. Python supports modules and packages, which encourages program modularity and code reuse. The Python interpreter and the extensive standard library are available in source or binary form without charge for all major platforms, and can be freely distributed.*   >   > *Often, programmers fall in love with Python because of the increased productivity it provides. Since there is no compilation step, the edit-test-debug cycle is incredibly fast. Debugging Python programs is easy: a bug or bad input will never cause a segmentation fault. Instead, when the interpreter discovers an error, it raises an exception. When the program doesn't catch the exception, the interpreter prints a stack trace. A source level debugger allows inspection of local and global variables, evaluation of arbitrary expressions, setting breakpoints, stepping through the code a line at a time, and so on. The debugger is written in Python itself, testifying to Python's introspective power. On the other hand, often the quickest way to debug a program is to add a few print statements to the source: the fast edit-test-debug cycle makes this simple approach very effective.*And here is an unpretentious glossary for the technical terms from above: - Programming language: a formal language designed to communicate instructions to a computer. A sequence of instructions that specifies how to perform a computation is called a program. - Interpreted language: a program in an interpreted language is executed or interpreted by an interpreter program. This interpreter executes the program source code, statement by statement. - Compiled language: a program in a compiled language is first explicitly translated by the user into a lower-level machine language executable (with a compiler) and then this program can be executed. - Python interpreter: an interpreter is the computer program that executes the program. The most-widely used implementation of the Python programming language, referred as CPython or simply Python, is written in C (another programming language, which is lower-level and compiled). - High-level: a high-level programming language has a strong abstraction from the details of the computer and the language is independent of a particular type of computer. A high-level programming language is closer to human languages than to the programming language running inside the computer that communicate instructions to its hardware, the machine language. The machine language is a low-level programming language, in fact, the lowest one.  - Object-oriented programming: a programming paradigm that represents concepts as "objects" that have data fields (attributes that describe the object) and associated procedures known as methods. - Semantics and syntax: the term semantics refers to the meaning of a language, as opposed to its form, the syntax. - Static and dynamic semantics: static and dynamic refer to the point in time at which some programming element is resolved. Static indicates that resolution takes place at the time a program is written. Dynamic indicates that resolution takes place at the time a program is executed. - Static and dynamic typing and binding: in dynamic typing, the type of the variable (e.g., if it is an integer or a string or a different type of element) is not explicitly declared, it can change, and in general is not known until execution time. In static typing, the type of the variable must be declared and it is known before the execution time.  - Rapid Application Development: a software development methodology that uses minimal planning in favor of rapid prototyping. - Scripting: the writing of scripts, small pieces of simple instructions (programs) that can be rapidly executed. - Glue language: a programming language for writing programs to connect software components (inluding programs written in other programming languages). - Modules and packages: a module is a file containing Python definitions (e.g., functions) and statements. Packages are a way of structuring Python’s module namespace by using “dotted module names”. For example, the module name A.B designates a submodule named B in a package named A. To be used, modules and packages have to be imported in Python with the import function. Namespace is a container for a set of identifiers (names), and allows the disambiguation of homonym identifiers residing in different namespaces. For example, with the command `import math`, we will have all the functions and statements defined in this module in the namespace '`math.`', for example, `math.pi` is the $\pi$ constant and `math.cos()`, the cosine function. - Program modularity and code reuse: the degree that programs can be compartmentalized (divided in smaller programs) to facilitate program reuse. - Source or binary form: source refers to the original code of the program (typically in a text format) which would need to be compiled to a binary form (not anymore human readable) to be able to be executed. - Major platforms: typically refers to the main operating systems (OS) in the market: Windows (by Microsoft), Mac OSX (by Apple), and Linux distributions (such as Debian, Ubuntu, Mint, etc.). Mac OSX and Linux distros are derived from, or heavily inspired by, another operating system called Unix. - Edit-test-debug cycle: the typical cycle in the life of a programmer; write (edit) the code, run (test) it, and correct errors or improve it (debug). The read–eval–print loop (REPL) is another related term. - Segmentation fault: an error in a program that is generated by the hardware which notifies the operating system about a memory access violation. - Exception: an error in a program detected during execution is called an exception and the Python interpreter raises a message about this error (an exception is not necessarily fatal, i.e., does not necessarily terminate or break the program). - Stack trace: information related to what caused the exception describing the line of the program where it occurred with a possible history of related events. - Source level debugger: Python has a module (named pdb) for interactive source code debugging. - Local and global variables: refers to the scope of the variables. A local variable is defined inside a function and typically can be accessed (it exists) only inside that function unless declared as global.  Why Python and not 'X' (put any other language here)Python is not the best programming language for all needs and for all people. There is no such language.   Now, if you are doing scientific computing, chances are that Python is perfect for you because (and might also be perfect for lots of other needs):1. Python is free, open source, and cross-platform.  2. Python is easy to learn, with readable code, well documented, and with a huge and friendly user community. 3. Python is a real programming language, able to handle a variety of problems, easy to scale from small to huge problems, and easy to integrate with other systems (including other programming languages).4. Python code is not the fastest but Python is one the fastest languages for programming. It is not uncommon in science to care more about the time we spend programming than the time the program took to run. But if code speed is important, one can easily integrate in different ways a code written in other languages (such as C and Fortran) with Python.5. The IPython Notebook is a versatile tool for programming, data visualization, ploting, simulation, numeric and symbolic mathematics, and writting for daily use.  The Zen of PythonThe core philosophy of the Python language (including its humor) is stated in the following document which you can get by starting Python and executing `import this` (PEP 20, The Zen of Python):<jupyter_code>import this<jupyter_output>The Zen of Python, by <NAME>

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!<jupyter_text>The IPython NotebookThe [IPython Notebook](http://ipython.org/) is an interactive environment for scientific programming in [Python](http://python.org/) which has revolutionized the way Python has been used (and other languages as well). The official citation for the IPython Notebook is:> <NAME>, <NAME>, IPython: A System for Interactive Scientific Computing, Computing in Science and Engineering, vol. 9, no. 3, pp. 21-29, May/June 2007, doi:10.1109/MCSE.2007.53. URL: [http://ipython.org](http://ipython.org). [PDF](http://fperez.org/papers/ipython07_pe-gr_cise.pdf). Jupyter and the future of IPython¶In August 2015, IPython suffered a big split as part of its evolution: "As of IPython 4.0, the language-agnostic parts of the project: the notebook format, message protocol, qtconsole, notebook web application, etc. have moved to new projects under the name [Jupyter](https://jupyter.org/). IPython itself is focused on interactive Python, part of which is providing a Python kernel for Jupyter."  Python installation and tutorial for scientific computing- [How to install Python for scientific computing](http://nbviewer.ipython.org/github/demotu/BMC/blob/master/notebooks/PythonInstallation.ipynb)  - [Tutorial on Python for scientific computing](http://nbviewer.ipython.org/github/demotu/BMC/blob/master/notebooks/PythonTutorial.ipynb)  To learn more about PythonThere is a lot of good material in the internet about Python for scientific computing, some of them are:   - [How To Think Like A Computer Scientist](http://www.openbookproject.net/thinkcs/python/english2e/) or [the interactive edition](http://interactivepython.org/courselib/static/thinkcspy/index.html) (book) - [Python Scientific Lecture Notes](http://scipy-lectures.github.io/) (lecture notes) - [Lectures on scientific computing with Python](https://github.com/jrjohansson/scientific-python-lectureslectures-on-scientific-computing-with-python) (lecture notes) - [IPython in depth: high-productivity interactive and parallel python](http://youtu.be/bP8ydKBCZiY) (video lectures)<jupyter_code>from IPython.display import Image
Image(url='http://imgs.xkcd.com/comics/python.png')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.054308867071840426, 'fraction_numerical': 0.0038959015116097864, 'mean_word_length': 4.933888118354138, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 22, 'https://': 2, 'lorem ipsum': 0, 'www.': 3, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '535131', 'license': 'MIT', 'n_tokens_mistral': 3060, 'n_tokens_neox': 2897, 'n_words': 1822, 'path': 'notebooks/PythonForScientificComputingOLD.ipynb', 'repo_name': 'jagar2/BMC', 'size': '12873'}