Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.03 KB | None | 0 0
  1.  
  2. import numpy as np
  3.  
  4. sequences = [[1, 2, 3, 1, 4, 5], [7, 8, 9, 2, 1, 4, 5], [7, 8, 9, 2, 1, 4]]
  5. embeddings = np.random.random((10,5))
  6.  
  7.  
  8. ##Rozšírte matice v tak aby každá mala rovnaký
  9. ##rozmer podľa maximálnej dĺžky zoznamu doplnením 0 hodnôt a spojte ich do výslednej matice data
  10. ## o rozmeroch počet sekvencií x max. dĺžka sekvencie x 5
  11.  
  12. zoznam = [];
  13. biggestMatrix = 0;
  14. for s in sequences:
  15.     v = np.random.random((len(s),5))
  16.     for i,a in enumerate(s):
  17.        v[i] = embeddings[a]
  18.     if biggestMatrix < v.shape[0]:
  19.          biggestMatrix = v.shape[0]
  20.     zoznam.append(v)
  21.  
  22. for index,matica in enumerate(zoznam):
  23.     if (matica.shape[0] < biggestMatrix) : zoznam[index] = np.concatenate((zoznam[index], np.zeros((biggestMatrix - matica.shape[0];, 5))))
  24.    
  25. for index,matica in enumerate(zoznam):
  26.     if matica.shape[0] < biggestMatrix:
  27.         rozdiel = biggestMatrix - matica.shape[0];
  28.         rozsirovac = np.zeros((rozdiel, 5))
  29.         zoznam[index] = np.concatenate((zoznam[index], rozsirovac))
  30.  
  31. zoznam
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement