these notes are based on the awesome repository by Chip Huyen on some Python tips and Tricks.
Lambdas
- Lambda keyword used to create inline functions.
square_ld = lambda x: x * x
- Quick declaration makes
lambda
function ideal for use in callbacks and when functions are to be passed as arguments to other functions.
Map
map(fn,iterable)
applies thefn
to all elements of theiterable
and returns a map object.- Can also use map with more than one iterable. Eg: if we want to calculate the mean squared error of a simple linear function
f(x) = ax + b
, with the true labellabels
, the methods are equivalent.