[英]python inner function with argument
Can someone help me with this python code. 有人可以帮我这个Python代码。 I am a beginner with Python, good with java though. 我是Python的初学者,但是擅长Java。
def train_nn(iterations, batch_size, use_tf_mnist=False):
def perPartition(it):
if not use_tf_mnist:
train_data = RowData(it)
test_data = train_data
else:
from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets('MNIST_data', one_hot=True)
train_data = mnist.train
test_data = mnist.train
return create_nn(train_data, test_data, iterations, batch_size)
return perPartition
the caller only calls train_nn(ITERATIONS, BATCH_SIZE, USE_TF_MNIST)
. 呼叫者仅呼叫train_nn(ITERATIONS, BATCH_SIZE, USE_TF_MNIST)
。 So where does the inner function get its it argument from? 那么内部函数从哪里得到它的it参数呢?
train_nn
returns the perPartition
function as a result. train_nn
作为结果返回perPartition
函数。 It gets its argument when the caller later calls the function: 当调用方以后调用该函数时,它将获取其参数:
trained = train_nn(100, 50, False)
nn = trained(some_it)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.