-
Notifications
You must be signed in to change notification settings - Fork 0
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
Comments
@gvnnz 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
|
Queste le avevo gia' fatte, adesso faccio la matrice |
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]] |
@Ace-Miky quella di cui parli è una funzione che faremo dopo.
Buono, però le righe e le colonne sono invertite. Infatti nel tuo esempio 4x6 la funzione ritorna 6 righe e 4 colonne. |
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]] |
@Ace-Miky nice. Una domanda: perché fai |
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))
|
@Ace-Miky crea la funzione
make_matrix
che prende in input due valori:num_rows
enum_columns
e ritorna una matrice numerica con tutti i valori settati a 0. Esempio:The text was updated successfully, but these errors were encountered: