I am trying to run the following code but there was an error. The following code was run in for Python3 using Spyder.
def create_batches(data_size, batch_size, shuffle=True): """create index by batches.""" batches =  ids = range(data_size) if shuffle: random.shuffle(ids) for i in range(data_size // batch_size): start = i * batch_size end = (i + 1) * batch_size batches.append(ids[start:end]) # the batch of which the length is less than batch_size rest = data_size % batch_size if rest > 0: batches.append(ids[-rest:] + [-1] * (batch_size - rest)) # -1 as padding return batches
The errror was:
TypeError: unsupported operand type(s) for +: 'range' and 'list'
Does anyone know how to solve this problem?