- Numpy+Scipy+Matplotlib=Matlab
- AI in Geosciences
- Computational Interpretation Group
- University of Science and Technology of China
- Xinming Wu
- 10/09/2020

- open-source web application: https://jupyter.org/

- create and share documents that contain live code, equations, visualizations and narrative text.

- Hit
`shift+enter`

to execute the cell

- Use
`!`

to excute shell commands, try`!ls`

,`!pwd`

,`!pip install ...`

- Use
`?`

(e.g.,`?numpy`

,`?numpy.mean()`

) for quick reference on syntax

- Change themes
`pip install jupyterthemes`

to install themes`jt -l`

to check the available themes`jt -t <theme>`

to set the theme`jt -r`

back to the default theme

- Notebook Extensions
- install: type
`pip install jupyter_contrib_nbextensions`

and then`jupyter contrib nbextension install`

- Table of Contents
- Hinterland
- Split cells

- install: type

- Using LaTeX for forumlas
- $\frac{\partial^2u}{\partial t^2}=c^2\frac{\partial^2 u}{\partial x^2}$

- Multicursor support

- Before you share
- Click “Cell > All Output > Clear”
- Click “Kernel > Restart & Run All”
- Wait for your code cells to finish executing and check ran as expected

- Export your notebooks
- Convert notebooks to html files using the File > Download as > HTML Menu option.
- Create a presentation like this one by using
`RISE`

- jupyter nbconvert numpy.ipynb --to slides --SlidesExporter.reveal_scroll=True
- Use the File > Download as > PDF menu to save your notebook as a PDF. (http://blog.juliusschulz.de/blog/ultimate-ipython-notebook#converting-notebook-to-latex-pdf)

- a fundamental package for scientific computing in Python
- a Python library includes a multidimensional array object (
**ndarray**), various derived objects, and**fast operations on arrays** - one of the top five Python packages, used in every field of science and engineering.
- install numpy:
`pip install numpy`

- import numpy:
`import numpy as np`

- fast
- the core of the scientific Python and PyData ecosystems
- the universal standard for working with numerical data in Python
- works well with Pandas, SciPy, Matplotlib, scikit-learn, scikit-image and most other data science and scientific Python packages
- all kinds of matrix operations, lots of built-in functions

`ndarray`

: the core of NumPy¶- a homogeneous n-dimensional array object (unlike Python sequences)
- The elements in a NumPy array are of the same data type and the same size in memory.

- NumPy arrays have a fixed size at creation, unlike Python lists (which can grow dynamically)
- a NumPy array has continuous memory

In [1]:

```
import numpy as np
data = np.array([1,2,3])
print(data)
```

[1 2 3]

`(number of rows, number of columns)`

¶In [2]:

```
data = np.array([[1,2],
[3,4],
[5,6]])
print(data)
```

[[1 2] [3 4] [5 6]]

- a NumPy array is stored in a contiguous block of memory
- two key concepts relating to memory: dimensions and
**strides** - strides are integer numbers of bytes to step in each dimension

In [3]:

```
data = np.array([[1,2,3],[4,5,6]], dtype='int16')
data.strides
```

Out[3]:

(6, 2)