Benoit Faure
Benoit Faure

Reputation: 3

Defining multiple variables inside one

Sorry I am new to python and I think I have seen someone, somewhere do something that resembled the following:

hiddenLayerinput = {
    units=64, 
    activation='relu', 
    input_dim=5
}

There is a syntax error at the = of units=64, Can I do that? And if yes, do you know whats wrong?

Thank you for any help

I am using Jupyter notebooks running python 3

Upvotes: 0

Views: 44

Answers (3)

Sushant
Sushant

Reputation: 3669

Python's dictionaries use {} and hence

hiddenLayerinput = {
    units=64, 
    activation='relu', 
    input_dim=5
}

is identified as a dictionary, = is SyntaxError you get. You need to change all the =s to :s

hiddenLayerinput = {
    "units":64, 
    "activation":'relu', 
    "input_dim":5
}

Edit - units, activation, input_dim are keys. If you have units, activation, input_dim as variables, you can remove the quotes and the values from those variables will be used as keys. Read more about dictionaries

Upvotes: 1

boandriy
boandriy

Reputation: 537

In your case hiddenLayerinput is a dictionary, you can use it as :

hiddenLayerinput = {
"units" : 64,
"activation": "relu"
"input_dim": 5
}

Then you can acces it as : hiddenLayerinput["units"] , and you will get value of "units" : 64

Upvotes: 2

Aragur
Aragur

Reputation: 68

Try this:

hiddenLayerinput = {
    units: 64, 
    activation: 'relu', 
    input_dim: 5,
}

Upvotes: 0

Related Questions