These two days to learn some of the Python application tutorials, see this writing:
return series.apply (lambda x: (x-min_val)/scale)-1.0)
What is a lambda? Never seen, so search online, basically say Lambda is an anonymous function, to solve the problem of the naming of simple functions, for example, you want to write a function in the program
def a (x):
x = x + 1 return
x
print (A (2))
So if you write like that, it's stupid. Oh no, it's too much, you still have to name the function for later reading, and if there's a way to do that without having to define the function and do it with just one line, it's cool. This is the role of the lambda, try the following:
A = lambda x:x + 1
The code looks a lot simpler. Perhaps this example does not explain the convenience of the lambda, but now look back at the top example, if you write a function
def a (x):
x = (x-min_val)/scale)-1.0
And this function is only used here once in the whole program, that is not many. In contrast to the topmost type, the convenience of the lambda points to a glance. Here's a concrete explanation: The x behind the lambda is the function argument, the formal parameter we often say, followed by the function entity, which can only be passed in a single argument when using a lambda function alone, that is, only one number is applied, and the map () Function can also apply a lambda function to a list:
foo = [2, 9, 8, MB]
Reslut = map (lambda x:x+1, foo)
print (list (reslut))
The results of help (map) are as follows
Make an iterator that uses the parameter calculation functions from each iterator. Stops when the shortest iterator is depleted. (Google translation)
The map () function produces an iterator that iterates through each element of the list, applies a lambda function to each element, and the list () function converts the return value of the iterator to the list output.
New Python beginners, the first blog, Welcome to the great God advice .... ..... ..... ...... ....... ....... ...