In [1]:
g = lambda x:x+1
print(g(1))
print(g(2))
In [2]:
foo = [2, 18, 9, 22, 17, 24, 8, 12, 27]
In [3]:
print(list(filter(lambda x: x % 3 == 0, foo)))
In [4]:
print([x for x in foo if x % 3 == 0]) # 如果可以使用for...in...if来完成的,坚决不用lambda。
In [5]:
print(list(map(lambda x: x * 2 + 10, foo)))
In [6]:
print([x * 2 + 10 for x in foo]) # 如果可以使用for...in...if来完成的,坚决不用lambda。
In [7]:
from functools import reduce
print(reduce(lambda x, y: x + y, foo))
In [8]:
import numpy as np
# 样本数据
coords1 = [1, 2, 3]
coords2 = [4, 5, 6]
np_c1 = np.array(coords1)
np_c2 = np.array(coords2)
# NumPy 内建函数
np.linalg.norm(np_c1 - np_c2)
Out[8]:
In [ ]: