ABSTRACT

In this chapter you learn how to write your own functions , similar to the functions provided by Python and NumPy. You learn how to write functions that process NumPy arrays efficiently. You learn how to write functions with variable numbers of arguments and how to pass function names (and the arguments of those functions) as an argument of a function you write. We introduce the concept of namespace , which isolates the names of variables and functions created inside a function from those created outside the function, with particular attention given to the subtle subject of passing mutable and immutable objects. You learn about anonymous functions ( lambda functions in Python) and their uses. We continue our discussion of objects and their associated methods and instance variables, here in the context of NumPy arrays. Finally, we illustrate some features of Python functions with their application to least squares fitting.