Joe
Joe

Reputation: 2438

Keras Dense input_shape as a list or a tuple

I've joined the ranks of software developers learning ML through TensorFlow and Keras, and one detail that keeps bothering me as I work through tutorials is the two flavors of specifying the input_shape to the first layer of a Sequential model:

# input_shape as a list
layer0 = tensorflow.keras.layers.Dense(units=1, input_shape=[1])

vs.

# input_shape as a tuple
layer0 = tensorflow.keras.layers.Dense(units=1, input_shape=(1,))

This appears to be functionally equivalent, but I'm not sure why, nor do I understand why both forms are used but the latter form (tuple) seems to be preferred.

Upvotes: 2

Views: 1151

Answers (1)

Kaveh
Kaveh

Reputation: 4970

It actually does not matter to use which one of them. Both are accepted and the result is the same.

As you said, tuple is preferred due to immutability. The major difference between tuples and lists is that a list is mutable, whereas a tuple is immutable. This means that a list can be changed, but a tuple cannot.

Upvotes: 1

Related Questions