elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Trabajando con las ramas de git (tercera parte)


+  Foro de elhacker.net
|-+  Programación
| |-+  Scripting
| | |-+  matrices en python
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: matrices en python  (Leído 2,101 veces)
py.cba

Desconectado Desconectado

Mensajes: 3


Ver Perfil
matrices en python
« en: 23 Noviembre 2016, 15:17 pm »

hola, perdon las molestias necesito una ayuda. Yo obtengo mi matriz asi:
Código
  1. matriz = []
  2. filas = int(raw_input("cantidad de filas: "))
  3. columnas = int(raw_input("cantidad de columnas: "))
  4. for i in range(filas):
  5.  matriz.append([0]*columnas)
  6. for f in range(filas):
  7.  for c in range(columnas):
  8.    matriz[f][c] = int(raw_input("elemento [%d,%d]: " % (f,c)))
  9.    if (filas,columnas)<0 and (filas,columnas)>17:
  10.      break
  11.  
  12. print "matriz ingresada", matriz

Y necesito que se imprima en vez de como listas como una matriz y me olvide como se hacia. Muchas gracias


Mod: Los códigos deben ir en etiquetas GeSHi


« Última modificación: 24 Noviembre 2016, 07:38 am por engel lex » En línea

Once

Desconectado Desconectado

Mensajes: 120


Ver Perfil WWW
Re: matrices en python
« Respuesta #1 en: 24 Noviembre 2016, 04:22 am »

Solo tienes que imprimir fila a fila:

Código
  1. matriz = []
  2. filas = int(raw_input("cantidad de filas: "))
  3. columnas = int(raw_input("cantidad de columnas: "))
  4. for i in range(filas):
  5.  matriz.append([0]*columnas)
  6. for f in range(filas):
  7.  for c in range(columnas):
  8.    matriz[f][c] = int(raw_input("elemento [%d,%d]: " % (f,c)))
  9.    if (filas,columnas)<0 and (filas,columnas)>17:
  10.      break
  11.  
  12. print "matriz ingresada", matriz
  13. for fila in matriz:
  14.    print " ".join(map(str, fila))

Saludos!


En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
matrices en python...
Scripting
BloodyDark 5 17,585 Último mensaje 1 Mayo 2010, 07:45 am
por leogtz
Matrices (python)
Scripting
facu_m 2 10,806 Último mensaje 8 Noviembre 2010, 23:30 pm
por Yeison.Eng
[Python] - Matrices. « 1 2 »
Scripting
Meta 17 17,213 Último mensaje 16 Noviembre 2010, 20:04 pm
por Novlucker
Python -- Creación de Matrices
Programación General
scyssor91 0 1,770 Último mensaje 13 Abril 2016, 20:17 pm
por scyssor91
Programa producto matrices python
Scripting
ra3 2 4,809 Último mensaje 30 Octubre 2017, 04:17 am
por BortizF
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines