-14

I have the following code:

print ([12,2][0])

The result is 12

print ([12,2][1])

The result is 2. Why?

Question update

I can't understand:

target_f = self.model.predict(state)
target_f[0][action] = target

https://github.com/keon/deep-q-learning/blob/master/dqn.py#L51

Why does target_f have an index [0] then another index [action]? What is this doing?

In my C programming experience, it should be a 2D array index. Is it the same here?

Boann
  • 48,794
  • 16
  • 117
  • 146
Mark
  • 325
  • 1
  • 16

1 Answers1

0

It is because [12, 2] is a list, and next notation: [0] or [1] is indexing.

You can test it if you try to print: print([12, 2][2]) you should get index out of range error.

EDIT: to answer your second question:

It is hard to say. target_f = self.model.predict(state) - it is some kind of structure and I can't find information about this structure in the link you put above.

But we can consider some similar structure. Let's say you have:

target_f = [{'action': 'value1', 'action2': 'valuex'}, {'action': 'value2', 'another_key': 'another_value'}]

In your code target_f[0][action] = target:

[0] is index in list. It stands for fist element of list: {'action': 'value1', 'action2': 'valuex'}

[action] is key in the dictionary. It stands for value1.

Since you are typing: target_f[0][action] = target thats mean you want to update your value1 by new value target. Your new stucture will looks like that:

target_f = [{'action': target, 'action2': 'valuex'}, {'action': 'value2', 'another_key': 'another_value'}]
Relandom
  • 1,029
  • 2
  • 9
  • 16