{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"(sec:scientific:libraries)=\n",
"# Scientific Libraries with Python\n",
"\n",
"\n",
"\n",
"Although coding with Python is very versatile and allows many advanced features that are useful when manipulating massive data (a common task in science), Python is still a multipurpose language, what implies that scientific routines and functions cannot (should not) be supported within its basic core. Nevertheless, there are many different scientific libraries that can extend the capabilities of Python to scientific implementations in a natural way. One of the most used libraries is NumPy. This introduce the array object as a generalization of Python nested lists. This new object has many linear algebra operations implemented as methods or attributes. This operations are implemented at the low level through fast highly optimized algorithms. \n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[](sec:scientific:libraries)"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"## Python+NumPy\n",
"In this way, Python+NumPy can be seen as a framework to implement numerical code as linear algebra abstractions which replaces the slow Python loops. The contrary is also true. In this framework each algorithm must be designed to try to avoid the use of Python loops like `for` or `while`.\n",
"\n",
"An ideal program implemented in Python+NumPy does not have explicit Python loops, but only linear algebra abstractions. "
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## Extended Python+Numpy framework\n",
"All the other high level packages for scientific computation are designed to work around the linear algebra abstractions of the Python+NumPy framework\n",
"* Pandas add labels to the Numpy arrays.\n",
"* Mathplotlib plotting library. Ti visualize arrays in 1, 2 and 3 dimensions\n",
"* SciPy, intended for manipulating NumPy arrays more efficiently and for extending and including numerical methods, respectively. \n",
"\n",
"\n",
"Another less used libraries like SymPy are intended for manipulating analytical expressions, i.e. a CAS (Computer Algebraic System).\n",
"\n",
"\n",
"Installation of these libraries is often an easy task. In most of the Linux distros you should find them in the official repositories.\n",
"\n",
"Avoid loops. Use abstractions"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"## Official Pages\n",
"\n",
"See the official pages of the libraries for new versions, news and manuals.\n",
"\n",
"**NumPy:**\n",
"\n",
"[http://www.numpy.org/](http://www.numpy.org/)\n",
"\n",
"**SciPy**\n",
"\n",
"[http://www.scipy.org/](http://www.scipy.org/)\n",
"\n",
"**SymPy**\n",
"\n",
"[http://www.sympy.org/](http://www.sympy.org/)\n",
"\n",
"**Anaconda**\n",
"\n",
"[https://www.anaconda.com/](https://www.anaconda.com/)\n",
"\n",
"Anaconda is a self-cointained Python distribution that integrates many standard scientific libraries with Python, along with some generic libraries like MongoDB\n",
"\n",
"\n",
"There are many different scientific libraries for Python with many different uses, even for very specific tasks. However, as we are interested in general numerical methods, we will focus only on NumPy and Scipy\n",
"\n",
"La forma recomendada de importar los diferentes módulos y el uso de sus métodos y atributos suele resumirse en _Cheat Sheets_. Para Python científico recomendamos las elaboradas por [Data Camp](https://learn.datacamp.com/), que pueden consultarse [aquí](https://drive.google.com/drive/folders/1jt_fDBA8GneCVVH874Th5_491Jc6GYXJ?usp=sharing)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"```{contents}\n",
":depth: 2\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"- - - "
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"
\n", " | even | \n", "odd | \n", "
---|---|---|
0 | \n", "0 | \n", "1 | \n", "
1 | \n", "2 | \n", "3 | \n", "
2 | \n", "4 | \n", "5 | \n", "
3 | \n", "6 | \n", "7 | \n", "
4 | \n", "8 | \n", "9 | \n", "