Error <Generator Object <genexpr> when reading Python matrix

Asked

Viewed 85 times

-3

I want to read matrix by placing the commas to separate the numbers, but when I ask to show the matrix, it gives this error:

<generator object <genexpr>

That never happened to me, I have no idea how to regularize. Follow the code below:

leia =input('Digite a dimensão da matriz: ')
vet = [float (x) for x in leia.split(',')]
matriz = []

for i in range (len(vet)):
    linha =[]
    linha.append(float(x) for x in input(f'Digite a linha {i}: ').split(','))
    matriz.append(linha)
    
print('Matriz digitada:')
for linha in matriz:
    print(linha)
  • read =input('Enter matrix dimension: ') vet = [float (x) for x in leia.split(',')] matrix = [] for i in range (Len(vet)): line =[] line.append(float(x) for x in input(f'Enter line {i}: '). split(',')) matrix.append(line) print('Typed matrix:') for line in matrix: print(line)

  • Change the line linha.append(float(x) for x in input(f'Digite a linha {i}: ').split(',')) for linha.extend(float(x) for x in input(f'Digite a linha {i}: ').split(','))

1 answer

-1


You need to use an object tuple() or list() to convert the result of the expression that is generating its matrix, more precisely in its for.

code working:

leia = input('Digite a dimensão da matriz: ')
vet = [float(x) for x in leia.split(',')]
matriz = []

for i in range(len(vet)):
    linha = []
    linha.append(tuple(float(x) for x in input(f'Digite a linha {i}: ').split(',')))
    matriz.append(linha)

print('Matriz digitada:')
for linha in matriz:
    print(linha)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.