예제 #1
0
    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)
예제 #2
0
 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)
예제 #3
0
    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)
예제 #4
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())
예제 #5
0
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()
예제 #6
0
 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)
예제 #7
0
    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)
예제 #8
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')    
예제 #9
0
    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
예제 #10
0
    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
예제 #11
0
    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
예제 #12
0
파일: graph.py 프로젝트: Ikonsty/Home-Work
    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]
예제 #13
0
    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
예제 #14
0
    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
예제 #15
0
 def __init__(self, rows, cols):
     self.__arr = Array2D(rows, cols)
예제 #16
0
파일: board.py 프로젝트: shakhovm/TicTacToe
 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] = '-'
예제 #17
0
 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)
예제 #19
0
 def __init__(self, num_rows, num_cols):
     self._mazeCells = Array2D(num_rows, num_cols)
     self._startCell = None
     self._exitCell = None
예제 #20
0
파일: grade.py 프로젝트: H4wking/lab11
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()):
예제 #21
0
 def __init__(self, nrows, ncols):
     self._grid = Array2D(nrows, ncols)
     self.clear(0)
예제 #22
0
파일: maze.py 프로젝트: glibesyck/Maze
 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
예제 #23
0
 def __init__(self, num_rows, num_cols):
     self.maze_cells = Array2D(num_rows, num_cols)
     self.start_cell = None
     self.exit_cell = None
예제 #24
0
파일: life.py 프로젝트: H4wking/lab11
 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())
예제 #25
0
 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)