def __init__(self,rens,cols,generaciones,poblacion): self.largo = cols self.alto = rens self.grid = Array2D( self.alto , self.largo,0 ) self.generaciones = generaciones for celula in poblacion: self.grid.set_item(celula[0],celula[1],self.CELULA_VIVA)
def __init__(self, n_rows, n_cols): """ Creates the game grid and initializes the cells to dead. :param num_rows: the number of rows. :param num_cols: the number of columns. """ # Allocates the 2D array for the grid. self._image = Array2D(n_rows, n_cols)
def __init__(self, num_rows, num_cols): """ Creates the grid and initiates all cells to 0 :param num_rows: number of rows :param num_cols: number of columns """ self._grid = Array2D(num_rows, num_cols) self.clear(0)
def __init__(self, num_rows, num_cols): """ Creates the game grid and initializes the cells to dead. :param num_rows: the number of rows. :param num_cols: the number of columns. """ # Allocates the 2D array for the grid. self._grid = Array2D(num_rows, num_cols) # Clears the grid and set all cells to dead. self.configure(list())
def main(): arr = Array(7) arr.to_string() print(f"El arr es de {arr.length()} elementos") arr.set_item( 3 , 11 ) arr.to_string() print(f"Elem. en la pos 3 es: { arr.get_item(3) }") arr.clearing( 55 ) arr.to_string() arr2d = Array2D(4,4) arr2d.to_string()
def setUp(self): self.data = np.load('data.npy') self.short_data = [[1, 0], [0, 1], [1, 1]] self.D2data = Array2D(3, 2) for y in range(3): for x in range(2): self.D2data[y, x] = self.short_data[y][x] self.xy_dict = dict() self.xy_dict[0] = 1 self.xy_dict[1] = 1 self.graph = GraphADT(self.data) self.short_graph = GraphADT(self.short_data)
def __init__(self, nrows, ncols): """ Creates the GrayscaleImage grid and initializes the cells to 0 value. :param nrows: the number of rows. :param ncols: the number of columns. """ # Allocates the 2D array for the grid. self._grid = Array2D(nrows, ncols) self.rows = nrows self.cols = ncols # Clears the grid and set all cells to dead. self.clear(0)
def test_2D_array(self): '''Testing 2D array class''' arr = Array2D(10, 5) self.assertIsInstance(arr, Array2D) self.assertEqual(arr.num_rows(), 10) self.assertEqual(arr.num_cols(), 5) arr[(0, 0)] = 'green' self.assertEqual(arr[(0, 0)], 'green') arr.clear('red') self.assertEqual(arr[(0, 0)], 'red')
def overall_statistics(): ''' Summarizing all the statistics collected into one overall statistics (2D array) Adding the result to class dictionary ''' overall_stat = Array2D(264, 2) overall_stat.clear(0) for key in StatisticsADT.STATISTICS: for i in range(264): overall_stat[(i, 0)] = StatisticsADT.STATISTICS[key][(i, 0)] overall_stat[(i, 1)] += StatisticsADT.STATISTICS[key][(i, 1)] StatisticsADT.STATISTICS['overall'] = overall_stat
def __init__(self, archivo_inicio): archivo = open(archivo_inicio, 'rt') self.__laberinto = Array2D(int(archivo.readline().strip()), int(archivo.readline().strip()), '1') self.__laberinto.clearing('1') # todo pared self.__entrada = [] self.__salida = [] self.__camino = Stack() self.__previa = None lineas = archivo.readlines() for ren in range(len(lineas)): lineas[ren] = lineas[ren].strip() col = 0 for cell in lineas[ren].split(','): self.__laberinto.set_item(ren, col, cell) col += 1
def read_file(self): ''' Reading the csv and saving its content into 2D array contents: 2D array with data from csv table ''' with open(self._filename, "r") as f: reader = csv.reader(f) contents = Array2D(264, 64) i = 0 for row in reader: if len(row) > 3 and row[0] != "Country Name": for j in range(64): contents[(i, j)] = row[j] i += 1 self._contents = contents
def __init__(self, _list=[[]]): """ type(_list) = list[lists] Giving a list of lists of tuples and initialize a graph Each inside list represent one word """ word_len = [] for word in _list: for p in word: if type(p) != tuple or len(p) != 2: raise TypeError("List must contains only points") word_len.append(len(word)) self.graph_lst = _list len_rows = len(_list) len_cols = max(word_len) self.graph = Array2D(len_rows, len_cols) for r in range(len(_list)): for c in range(len(_list[r])): self.graph[(r, c)] = _list[r][c]
def country_summary(self): ''' Processing the content of csv file. Summarizing the quantity of air traffic of all years and saving the results into new 2D array Adding the result of the research to class dictionary ''' countries_sum = Array2D(264, 2) for i in range(264): countries_sum[(i, 0)] = self._contents[(i, 0)] summary = 0 for j in range(5, 64): summary += float("0" + self._contents[(i, j)]) countries_sum[(i, 1)] = summary self._countries_sum = countries_sum StatisticsADT.STATISTICS[self._key] = self._countries_sum
def __init__(self, rens, cols, generaciones, poblacion): self.largo = cols self.alto = rens self.grid = Array2D(self.alto, self.largo, 0) self.generaciones = generaciones for celula in poblacion: self.grid.set_item(celula[0], celula[1], self.CELULA_VIVA) def configura_generacion(self, nueva_poblacion): self.grid.clearing() for celula in nueva_poblacion: self.grid.set_item(celula[0], celula[1], self.CELULA_VIVA) def imprime_grid(self): for r in range(self.grid.get_num_rows()): for c in range(self.grid.get_num_cols()): if self.grid.get_item(r, c) == 0: print("░░", end="") else: print("▓▓", end="") print("") def get_num_rows(self): return self.alto def get_num_cols(self): return self.largo def set_celula_muerta(self, row, col): self.grid.set_item(row, col, self.CELULA_MUERTA) def set_celula_viva(self, row, col): self.grid.set_item(row, col, self.CELULA_VIVA) def get_is_viva(self, row, col): return self.grid.get_item(row, col) == self.CELULA_VIVA
def __init__(self, rows, cols): self.__arr = Array2D(rows, cols)
def __init__(self): self.field = Array2D(3, 3) for i in range(self.field.num_rows()): for j in range(self.field.num_cols()): self.field[i, j] = '-'
def __init__(self, nrows: int, ncols: int): """ Represents the future image as 2D Array. """ self.image_array = Array2D(nrows, ncols) self.clear(0)
def __init__(self, nrows, ncols): #creates 2D array and clear it self._img = Array2D(nrows, ncols) self._img.clear(0)
def __init__(self, num_rows, num_cols): self._mazeCells = Array2D(num_rows, num_cols) self._startCell = None self._exitCell = None
from arrays import Array2D # Open the text file for reading. grade_file = open("grade.txt", "r") # Extract the first two values which indicate the size of the array. num_students = int(grade_file.readline()) num_exams = int(grade_file.readline()) # Create the 2 -D array to store the grades. exam_grades = Array2D(num_students, num_exams) # Extract the grades from the remaining lines. i = 0 for student in grade_file: grades = student.split() for j in range(num_exams): exam_grades[i, j] = int(grades[j]) i += 1 # Close the text file. grade_file.close() # Compute each student's average exam grade. for i in range(num_students): # Tally the exam grades for the ith student. total = 0 for j in range(num_exams): total += exam_grades[i, j] # Compute average for the ith student. exam_avg = total / num_exams print("{:2d}: {:6.2f}".format(i + 1, exam_avg)) # Add 2 points to every grade. for row in range(exam_grades.num_rows()):
def __init__(self, nrows, ncols): self._grid = Array2D(nrows, ncols) self.clear(0)
def __init__(self, num_rows, num_cols): """Creates a maze object with all cells marked as open.""" self._maze_cells = Array2D(num_rows, num_cols) self._start_cell = None self._exit_cell = None
def __init__(self, num_rows, num_cols): self.maze_cells = Array2D(num_rows, num_cols) self.start_cell = None self.exit_cell = None
def __init__(self, numRows, numCols): # Allocate the 2 -D array for the grid. self._grid = Array2D(numRows, numCols) # Clear the grid and set all cells to dead. self.configure(list())
def __init__(self, nrows, ncols): self._rows = nrows self._cols = ncols self._image = Array2D(nrows, ncols) # Set all the values to 0 self.clear(0)