我學習tensorflow建立一個神經網絡,我有樓下的示例代碼:蟒蛇lambda語法錯誤
import tensorflow as tf
# get weight of a layer, and add the l2 regularizer of the weight to the collection of 'losses'
def get_weight(shape, lambda):
var = tf.Variable(tf.random_normal(shape), dtype = tf.float32)
tf.add_to_collection('losses', tf.contrib.layers.l2_regularizer(lambda)(var))
return var
我使用Python 3.5運行此腳本,但我得到這個:
File "4.4.2.py", line 4
def get_weight(shape, lambda):
^
SyntaxError: invalid syntax
'lambda'是python中的關鍵字。你必須選擇一個不同的變量名稱。 – jtbandes
lambda是Python中的一個保留字,您不應該將它用作參數名稱。 –