0

In the following code, the shape of state is (4,1). I am aware with the .reshape() command, but cannot understand the (-1, *state.shape) in the following expression. (I am using a tutorial to understand Deep Q-Learning and this command is part of that tutorial.). I can see what it does, but the syntax is new to me

self.model.predict(np.array(state).reshape(-1, *state.shape))[0]

Furthermore, is there any particular shape we should use for .predict()

User007
  • 48
  • 7
  • Does this answer your question? [What does \*\* (double star/asterisk) and \* (star/asterisk) do for parameters?](https://stackoverflow.com/questions/36901/what-does-double-star-asterisk-and-star-asterisk-do-for-parameters) – Nicolas Gervais Aug 10 '20 at 08:58

2 Answers2

1

Keras expects the input data to be in the dimension form of (M, D) where M is the batch size and D is the number of features.

If this is one single batch example with 4 features, this is what the reshape() command is doing here for you, ie. changing the (4,1) shape to (1,4) form.

SJa
  • 487
  • 4
  • 14
1

The *-operator unpacks elements out of the shape tuple.

The reshape command with '-1', followed by the original shape is a trick to add an additional dimension.

For example shape (4,1) becomes (1,4,1).

What shape does predict() require? Documentation describes the x argument is "input samples", so expects a list/array where the first dimension is referring to individual samples.

caldweln
  • 126
  • 3