Advertisement
Guest User

Untitled

a guest
Feb 26th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. [[ 575.40625 984.40625 560.234375 936.0625 733.84375
  2. 725.9375 469.234375 828.046875 210.421875 522.4375 713.375
  3. 466.484375 679.8125 242.296875 645.328125 666.265625]
  4. [ 976.390625 668.46875 513.328125 769.359375 1343.65625
  5. 1068.3125 1206.21875 1447.484375 571.359375 420.71875
  6. 246.03125 333.15625 626.921875 615.03125 867.03125
  7. 1051.34375 ]
  8. [ 498.1875 1176.453125 670.609375 597.578125 765.078125
  9. 713.8125 825.84375 760.171875 667.015625 755.40625
  10. 1003.71875 687.921875 448.921875 574.90625 598.859375
  11. 487.09375 ]
  12. [ 564.203125 485.140625 652.625 740.875 465.875 1152.03125
  13. 623.15625 949.28125 722.515625 397.046875 529.03125 487.
  14. 427.109375 424. 495.734375 510.453125]]
  15.  
  16. def row_col_coords(index):
  17. # Convert bits 1, 3 and 5 to row
  18. row = 4*((index & 0b100000) > 0) + 2*((index & 0b1000) > 0) + 1*((index & 0b10) > 0)
  19. # Convert bits 0, 2 and 4 to col
  20. col = 4*((index & 0b10000) > 0) + 2*((index & 0b100) > 0) + 1*((index & 0b1) > 0)
  21. return (row, col)
  22.  
  23. In [114]: row_col_coords(45)
  24. Out[114]: (6, 3)
  25.  
  26. In [116]: row_col_coords(np.array([45, 46, 47, 48]))
  27. Out[116]: (array([6, 7, 7, 4]), array([3, 2, 3, 4]))
  28.  
  29. In [116]: data = 100 + np.arange(64.)
  30.  
  31. In [117]: row, col = row_col_coords(np.arange(64))
  32.  
  33. In [118]: a = np.empty((8, 8))
  34.  
  35. In [119]: a[row, col] = data
  36.  
  37. In [120]: a
  38. Out[120]:
  39. array([[ 100., 101., 104., 105., 116., 117., 120., 121.],
  40. [ 102., 103., 106., 107., 118., 119., 122., 123.],
  41. [ 108., 109., 112., 113., 124., 125., 128., 129.],
  42. [ 110., 111., 114., 115., 126., 127., 130., 131.],
  43. [ 132., 133., 136., 137., 148., 149., 152., 153.],
  44. [ 134., 135., 138., 139., 150., 151., 154., 155.],
  45. [ 140., 141., 144., 145., 156., 157., 160., 161.],
  46. [ 142., 143., 146., 147., 158., 159., 162., 163.]])
  47.  
  48. In [121]: a[::-1]
  49. Out[121]:
  50. array([[ 142., 143., 146., 147., 158., 159., 162., 163.],
  51. [ 140., 141., 144., 145., 156., 157., 160., 161.],
  52. [ 134., 135., 138., 139., 150., 151., 154., 155.],
  53. [ 132., 133., 136., 137., 148., 149., 152., 153.],
  54. [ 110., 111., 114., 115., 126., 127., 130., 131.],
  55. [ 108., 109., 112., 113., 124., 125., 128., 129.],
  56. [ 102., 103., 106., 107., 118., 119., 122., 123.],
  57. [ 100., 101., 104., 105., 116., 117., 120., 121.]])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement