The list doesn't change after the append


#1

Hello guys,
Actually I have a problem with this code:

import torch
import torch.nn as nn
import dataset_functions as df

grid_length = 13
‘’’
STEP 1: LOADING DATASET
‘’’

training_file = open(“data/raw_games_extra_small.dat”, ‘r’)
training_lines_list = []
for line in training_file:
moves = line.split()
training_lines_list.append(moves)

training_dataset, best_moves_dataset = [], []

temp_grid_flat = torch.zeros(grid_length*grid_length)
for training_str_list in training_lines_list:
c = 1
while (c<len(training_str_list)):
temp_grid_flat = df.get_resulting_grid_tensor(temp_grid_flat, training_str_list[c-1], 2, grid_length)
#print("1: ", temp_grid_flat )
training_dataset.append(temp_grid_flat)
best_moves_dataset.append( df.get_flat_index_move(training_str_list[c], grid_length) )
temp_grid_flat = df.get_resulting_grid_tensor(temp_grid_flat, training_str_list[c], 1, grid_length)
c = c + 2

print(training_dataset)

The first print returns temp_grid_flat with different elements but after the append when I print the training_dataset my list doesn’t change.
What Can I do to resolve this problem?
Thanks in advance.


(Vahid Mirjalili) #2

Could you put the code in code-block like the following, so we can see the indented blocks correctly:

type or paste code here
for loop:
     indented block