1. 程式人生 > >python的functools.partial的應用

python的functools.partial的應用

and 結果 ati 其他 part class orm tool true

functools.partial是類似於創造“可移動”函數的意思,參數的第一個是函數名,其他的是這個函數其他參數,例如:

generator_func = functools.partial(
        tf.random_uniform, [],
        minval=min_scale_ratio, maxval=max_scale_ratio,
        dtype=tf.float32, seed=seed)

 這時候的generator_func 就是移動函數名,類似於函數指針,可以傳參,但是經過"="號後就進行運算,然後返回值給賦值的,如:a=generator_func (),a就是tf.random_uniform運行得到的結果。

python的functools.partial的應用