Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. bboxes.shape => (32,125)
  2. x_cell.shape => (32,)
  3. y_cell.shape => (32,)
  4. output.shape => (13,13,32,125)
  5.  
  6. for i in range(32):
  7. output[x_cell[i], y_cell[i], i, :] = bboxes[i]
  8.  
  9. #eg shapes of indexing: output[(1,), (1,), (1,), :] = (125,)
  10.  
  11. output[x_cell,y_cell,np.arange(32)[:,None],:] = bboxes[:,None,:]
  12.  
  13. output[x_cell,y_cell,np.arange(32)[:,None]] = bboxes[:,None]
  14.  
  15. In [53]: # Setup
  16. ...: np.random.seed(0)
  17. ...: bboxes = np.random.rand(32,125)
  18. ...: x_cell = np.random.randint(0,13,(32,13))
  19. ...: y_cell = np.random.randint(0,13,(32,13))
  20. ...:
  21. ...: output = np.zeros((13,13,32,125))
  22. ...: for i in range(32):
  23. ...: output[x_cell[i], y_cell[i], i, :] = bboxes[i]
  24. ...:
  25. ...: out = np.zeros((13,13,32,125))
  26. ...: out[x_cell,y_cell,np.arange(32)[:,None]] = bboxes[:,None]
  27. ...:
  28. ...: print np.allclose(out, output)
  29. True
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement