---
jupyter:
jupytext:
text_representation:
extension: .Rmd
format_name: rmarkdown
format_version: '1.2'
jupytext_version: 1.11.5
kernelspec:
display_name: Python 3 (ipykernel)
language: python
name: python3
---
# Methods vs functions in NumPy
Many things are implemented in NumPy as both *functions* and *methods*. For
example, there is a `np.sum` function, that adds up all the elements:
```{python}
import numpy as np
```
```{python}
arr = np.array([1, 2, 0, 1])
np.sum(arr)
```
There is also a `sum` method of the numpy `array` object:
```{python}
type(arr)
```
```{python}
arr.sum()
```
Nearly all the method versions do the same thing as the function versions.
Examples are `mean`, `min`, `max`, `sum`, `reshape`. Choosing the
method or the function will usually depend on which one is easier to read.