def Convert(self, image): """ Arguments: --------- image: an Image instance Returns: ------- an instance of Input Description: ----------- The *image* arguments has 2 attributes: *label* which indicates the digit represented by the image, and *pixels* a matrix 14 x 14 represented by a list (first list is the first row, second list the second row, ... ), containing numbers whose values are comprised between 0 and 256.0. The function transforms this into a unique list of 14 x 14 items, with normalized values (that is, the maximum possible value should be 1). """ def norm_sublst(sublst): lst = [] # loop over 14 because pixels is a 14x14 matrix for i in range(1): for j in range(36): lst.append(sublst[i][j]) return lst i = Input() i.values = norm_sublst(image.pixels) return i
def Convert(self, image): """ Arguments: --------- image: an Image instance Returns: ------- an instance of Input Description: ----------- The *image* arguments has 2 attributes: *label* which indicates the digit represented by the image, and *pixels* a matrix 14 x 14 represented by a list (first list is the first row, second list the second row, ... ), containing numbers whose values are comprised between 0 and 256.0. The function transforms this into a unique list of 14 x 14 items, with normalized values (that is, the maximum possible value should be 1). """ # Replace line below by content of function values = [] # comp = [pixel/256.0 for pixel in sublist in image.pixels] for row in image.pixels: values += map(lambda x:x/256.0,row) ret = Input() ret.values = values return ret
def Convert(self, image): """ Arguments: --------- image: an Image instance Returns: ------- an instance of Input Description: ----------- The *image* arguments has 2 attributes: *label* which indicates the digit represented by the image, and *pixels* a matrix 14 x 14 represented by a list (first list is the first row, second list the second row, ... ), containing numbers whose values are comprised between 0 and 256.0. The function transforms this into a unique list of 14 x 14 items, with normalized values (that is, the maximum possible value should be 1). """ # flatten matrix into list new_input = Input() new_input.values = [pixel/256.0 for row in image.pixels for pixel in row] return new_input
def Convert(self, image): """ Arguments: --------- image: an Image instance Returns: ------- an instance of Input Description: ----------- The *image* arguments has 2 attributes: *label* which indicates the digit represented by the image, and *pixels* a matrix 14 x 14 represented by a list (first list is the first row, second list the second row, ... ), containing numbers whose values are comprised between 0 and 256.0. The function transforms this into a unique list of 14 x 14 items, with normalized values (that is, the maximum possible value should be 1). " new_pixels = [None for i in range(196)] for i in range(14): for j in range(14): new_pixels[i*14+j] = image.pixels[i][j] / 256.0 """ input = Input() input.values = image.pixels return input
def Convert(self, image): """ Arguments: --------- image: an Image instance Returns: ------- an instance of Input Description: ----------- The *image* arguments has 2 attributes: *label* which indicates the digit represented by the image, and *pixels* a matrix 14 x 14 represented by a list (first list is the first row, second list the second row, ... ), containing numbers whose values are comprised between 0 and 256.0. The function transforms this into a unique list of 14 x 14 items, with binary values, i.e., 1 if the pixel is mostly dark, or 0 if it's mostly light. """ # Replace line below by content of function values = [] for i in range(len(image.pixels)): for j in range(len(image.pixels[i])): if image.pixels[i][j] >= 128: pixel = 1 else: pixel = 0 values.append(pixel) input = Input() input.values = values return input
def Convert(self, image): """ Arguments: --------- image: an Image instance Returns: ------- an instance of Input Description: ----------- The *image* arguments has 2 attributes: *label* which indicates the digit represented by the image, and *pixels* a matrix 14 x 14 represented by a list (first list is the first row, second list the second row, ... ), containing numbers whose values are comprised between 0 and 256.0. The function transforms this into a unique list of 14 x 14 items, with normalized values (that is, the maximum possible value should be 1). """ # Replace line below by content of function values = [] for i in range(len(image.pixels)): for j in range(len(image.pixels[i])): values.append(image.pixels[i][j] / 256.0) input = Input() input.values = values return input
def Convert(self, image): outer = [] for i in image.pixels: for j in i: outer.append(j / 256.0) inp = Input() inp.values = outer return inp
def Convert(self, image): """ Arguments: --------- image: an Image instance Returns: ------- an instance of Input Description: ----------- The *image* arguments has 2 attributes: *label* which indicates the digit represented by the image, and *pixels* a matrix 14 x 14 represented by a list (first list is the first row, second list the second row, ... ), containing numbers whose values are comprised between 0 and 256.0. The function transforms this into a unique list of 14 x 14 items, with normalized values (that is, the maximum possible value should be 1). """ out = Input() for lst in image.pixels: for pixel in lst: out.values.append(pixel / 256.0) return out