Methods vs functions in NumPy
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:
import numpy as np
arr = np.array([1, 2, 0, 1]) np.sum(arr)
There is also a
sum method of the numpy
Nearly all the method versions do the same thing as the function versions.
reshape. Choosing the
method or the function will usually depend on which one is easier to read.