Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nuova funzione make_matrix per generare una matrice #10

Closed
gvnnz opened this issue Feb 26, 2024 · 7 comments
Closed

Nuova funzione make_matrix per generare una matrice #10

gvnnz opened this issue Feb 26, 2024 · 7 comments
Assignees
Labels
enhancement New feature or request

Comments

@gvnnz
Copy link
Owner

gvnnz commented Feb 26, 2024

@Ace-Miky crea la funzione make_matrix che prende in input due valori: num_rows e num_columns e ritorna una matrice numerica con tutti i valori settati a 0. Esempio:

make_matrix(4, 4) # [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
@gvnnz gvnnz added the enhancement New feature or request label Feb 26, 2024
@Ace-Miky
Copy link
Collaborator

Ace-Miky commented Feb 27, 2024

@gvnnz
Non e' piu' utile una funzione che ti da' tutte le righe e poi tutte le colonne per stabilire il vincitore vedendo se nelle liste c'e' una lista con i valori tutti uguali?

def get_all_matrix_rows(matrix):
    all_rows_matrix = []
    n = 0
    for i in range(len(matrix)):

        x = matrix[n]

        all_rows_matrix.append(x)
        n = n + 1
    return all_rows_matrix


def get_all_matrix_columns(matrix):
    all_column_matrix = []
    n = 0
    for i in range(len(matrix)):
        count = 0
        column_list = []
        for element in matrix:
            column_list.append(matrix[count][n])
            count = count + 1
        n = n + 1
        all_column_matrix.append(column_list)
    return all_column_matrix

@Ace-Miky
Copy link
Collaborator

Queste le avevo gia' fatte, adesso faccio la matrice

@Ace-Miky
Copy link
Collaborator

Ace-Miky commented Feb 27, 2024

@gvnnz

def make_matrix(num_rows, num_columns):
    matrice = []
    for i in range(num_columns):
        row = []
        for j in range(num_rows):
            number = 0
            row.insert(i, number)
        matrice.append(row)
    return matrice


print(make_matrix(4, 6))
[[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]

@gvnnz
Copy link
Owner Author

gvnnz commented Feb 28, 2024

Non e' piu' utile una funzione che ti da' tutte le righe e poi tutte le colonne per stabilire il vincitore vedendo se nelle liste c'e' una lista con i valori tutti uguali?

@Ace-Miky quella di cui parli è una funzione che faremo dopo. make_matrix è per inizializzare il programma e ci servirà molto quando vedremo gli oggetti.

def make_matrix(num_rows, num_columns):
    matrice = []
    for i in range(num_columns):
        row = []
        for j in range(num_rows):
            number = 0
            row.insert(i, number)
        matrice.append(row)
    return matrice

Buono, però le righe e le colonne sono invertite. Infatti nel tuo esempio 4x6 la funzione ritorna 6 righe e 4 colonne.

@Ace-Miky
Copy link
Collaborator

@gvnnz

L`avevo fatta cosi poi ho invertito...

def make_matrix(num_rows, num_columns):
    matrice = []
    for i in range(num_rows):
        row = []
        for j in range(num_columns):
            number = 0
            row.insert(i, number)
        matrice.append(row)
    return matrice


print(make_matrix(4, 6))
[[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]

@gvnnz
Copy link
Owner Author

gvnnz commented Feb 28, 2024

@Ace-Miky nice. Una domanda: perché fai row.insert(i, number)? Non basta un append? Perché poi i è l'indice della riga e non c'entra...

@Ace-Miky
Copy link
Collaborator

Ace-Miky commented Feb 29, 2024

def make_matrix(num_rows, num_columns):
    matrix = []
    for i in range(num_rows):
        row = []
        for j in range(num_columns):
            number = 0
            row.append(number)
        matrix.append(row)
    return matrix


print(make_matrix(4, 6))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants