A: reduce
from functools import reduce
def add(x):
return x+1
def mut(x):
return x**2
print(reduce(lambda f,g:lambda *a,**kw:g(f(*a,**kw)),[add,mut,add,mut])(1))
print(reduce(lambda f,g:lambda *a,**kw:f(g(*a,**kw)),[add,mut,add,mut])(1))
f*a **kw:表示传入的参数,个数,类型都任意,一种通用的表示方法:
第一种按着传入顺序执行顺序操作 因为 lambda f,g g(f()) + **2 + **2
第二种按着传入顺序逆序执行操作,因为lambda f,g f(g()) **2 + **2+
B:K.tile
grid_shape = K.shape(feats)[1:3]
grid_y = K.tile(K.reshape(K.arange(0, stop=grid_shape[0]), [-1, 1, 1, 1]), [1, grid_shape[1], 1, 1])
grid_x = K.tile(K.reshape(K.arange(0, stop=grid_shape[1]), [1, -1, 1, 1]), [grid_shape[0], 1, 1, 1])
grid=K.concatenate([grid_x,grid_y])
grid=K.cast(grid,K.dtype(feats))
第一句:获得grid_shape 的 width height
第二句:把height 扩成[h,1,1,1]的容器,并用扩充成 [h,w,1,1]
第三句:同样得到[h,w,1,1]
第四句:[h,w,1,2]
请尝试example 会更有感觉
a=13
aa=K.arange(0,stop=a)
print(aa)
aaa=K.reshape(aa,[-1,1,1,1])
print(aaa)
aaaa=K.tile(aaa,[1,15,1,1])
print(aaaa)
b=15
bb=K.arange(0,stop=b)
print(bb)
bbb=K.reshape(bb,[1,-1,1,1])
print(bbb)
bbbb=K.tile(bbb,[13,1,1,1])
print(bbbb)
ab=K.concatenate([aaaa,bbbb])
print(ab)
a=13res
result:
Using TensorFlow backend.
Tensor("arange:0", shape=(13,), dtype=int32)
Tensor("Reshape:0", shape=(13, 1, 1, 1), dtype=int32)
Tensor("Tile:0", shape=(13, 15, 1, 1), dtype=int32)
Tensor("arange_1:0", shape=(15,), dtype=int32)
Tensor("Reshape_1:0", shape=(1, 15, 1, 1), dtype=int32)
Tensor("Tile_1:0", shape=(13, 15, 1, 1), dtype=int32)
Tensor("concat:0", shape=(13, 15, 1, 2), dtype=int32)