Guest User

Untitled

a guest
May 24th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. matriz=[[1,2,4],[6,8,8],[9,10,12]]
  2.  
  3. matriz[0][0]=1
  4.  
  5. matriz[0][1]=2,3
  6.  
  7. matriz[0][2]=4,5,6,7
  8.  
  9. matriz[1][0]=8,9,10,11,12,13
  10.  
  11. matriz[1][1]=14,15,16,17,18,19,20,21
  12.  
  13. ...
  14.  
  15. numeros=[[1,2,4],[6,8,8],[9,10,12]]
  16. matriz = []
  17.  
  18. inicio = 1
  19. for fila in numeros:
  20. m_fila = []
  21. for n in fila:
  22. m_fila.append(tuple(range(inicio, inicio+n)))
  23. inicio += n
  24. matriz.append(m_fila)
  25.  
  26. >>> matriz
  27. [[(1,), (2, 3), (4, 5, 6, 7)],
  28. [(8, 9, 10, 11, 12, 13),
  29. (14, 15, 16, 17, 18, 19, 20, 21),
  30. (22, 23, 24, 25, 26, 27, 28, 29)],
  31. [(30, 31, 32, 33, 34, 35, 36, 37, 38),
  32. (39, 40, 41, 42, 43, 44, 45, 46, 47, 48),
  33. (49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60)]]
  34.  
  35. import numpy as np
  36. numeros=np.array([[1,2,4],[6,8,8],[9,10,12]])
  37. matriz = np.zeros(numeros.shape, dtype=object)
  38.  
  39. inicio = 1
  40. for i, fila in enumerate(numeros):
  41. for j, n in enumerate(fila):
  42. matriz[i][j] = tuple(range(inicio, inicio+n))
  43. inicio += n
  44.  
  45. >>> print(matriz)
  46. [[(1,) (2, 3) (4, 5, 6, 7)]
  47. [(8, 9, 10, 11, 12, 13) (14, 15, 16, 17, 18, 19, 20, 21)
  48. (22, 23, 24, 25, 26, 27, 28, 29)]
  49. [(30, 31, 32, 33, 34, 35, 36, 37, 38)
  50. (39, 40, 41, 42, 43, 44, 45, 46, 47, 48)
  51. (49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60)]]
Add Comment
Please, Sign In to add comment