The syntax definition of python is still very different from C++, matlab, and java.
1. Parentheses and function calls
def devided_3(x): return x/3.
print(a) #Result of call without parentheses: <function a at 0x139c756a8>
print(a(3)) #Result of bracketed call: 1
Without parentheses, the call is to the first address of the function in memory; with parentheses, the call is to the code block of the function in memory, and the body of the function is executed after inputting parameters.
2. Parentheses and class calls
class test(): y = 'this is out of __init__()' def __init__(self): = 'this is in the __init__()' x = test # x is the first address of the class location print() # Output class: this is out of __init__() x = test() # Instantiation of classes print() # Attributes of the output class:this is in the __init__() ;
3. function(#) (input)
def With_func_rtn(a): print("this is func with another func as return") print(a) def func(b): print("this is another function") print(b) return func func(2018)(11) >>> this is func with another func as return 2018 this is another function 11
In fact, this is most commonly used in convolutional neural networks:
def model(input_shape): # Define the input placeholder as a tensor with shape input_shape. X_input = Input(input_shape) # Zero-Padding: pads the border of X_input with zeroes X = ZeroPadding2D((3, 3))(X_input) # CONV -> BN -> RELU Block applied to X X = Conv2D(32, (7, 7), strides = (1, 1), name = 'conv0')(X) X = BatchNormalization(axis = 3, name = 'bn0')(X) X = Activation('relu')(X) # MAXPOOL X = MaxPooling2D((2, 2), name='max_pool')(X) # FLATTEN X (means convert it to a vector) + FULLYCONNECTED X = Flatten()(X) X = Dense(1, activation='sigmoid', name='fc')(X) # Create model. This creates your Keras model instance, you'll use this instance to train/test the model. model = Model(inputs = X_input, outputs = X, name='HappyModel') return model
summarize
The above is a small introduction to the Python function(#) (X) format and (#) in Python3.* Note, I hope to help you, if you have any questions please leave me a message, I will promptly reply to you. I would also like to thank you very much for your support of my website!