Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [[ 575.40625 984.40625 560.234375 936.0625 733.84375
- 725.9375 469.234375 828.046875 210.421875 522.4375 713.375
- 466.484375 679.8125 242.296875 645.328125 666.265625]
- [ 976.390625 668.46875 513.328125 769.359375 1343.65625
- 1068.3125 1206.21875 1447.484375 571.359375 420.71875
- 246.03125 333.15625 626.921875 615.03125 867.03125
- 1051.34375 ]
- [ 498.1875 1176.453125 670.609375 597.578125 765.078125
- 713.8125 825.84375 760.171875 667.015625 755.40625
- 1003.71875 687.921875 448.921875 574.90625 598.859375
- 487.09375 ]
- [ 564.203125 485.140625 652.625 740.875 465.875 1152.03125
- 623.15625 949.28125 722.515625 397.046875 529.03125 487.
- 427.109375 424. 495.734375 510.453125]]
- def row_col_coords(index):
- # Convert bits 1, 3 and 5 to row
- row = 4*((index & 0b100000) > 0) + 2*((index & 0b1000) > 0) + 1*((index & 0b10) > 0)
- # Convert bits 0, 2 and 4 to col
- col = 4*((index & 0b10000) > 0) + 2*((index & 0b100) > 0) + 1*((index & 0b1) > 0)
- return (row, col)
- In [114]: row_col_coords(45)
- Out[114]: (6, 3)
- In [116]: row_col_coords(np.array([45, 46, 47, 48]))
- Out[116]: (array([6, 7, 7, 4]), array([3, 2, 3, 4]))
- In [116]: data = 100 + np.arange(64.)
- In [117]: row, col = row_col_coords(np.arange(64))
- In [118]: a = np.empty((8, 8))
- In [119]: a[row, col] = data
- In [120]: a
- Out[120]:
- array([[ 100., 101., 104., 105., 116., 117., 120., 121.],
- [ 102., 103., 106., 107., 118., 119., 122., 123.],
- [ 108., 109., 112., 113., 124., 125., 128., 129.],
- [ 110., 111., 114., 115., 126., 127., 130., 131.],
- [ 132., 133., 136., 137., 148., 149., 152., 153.],
- [ 134., 135., 138., 139., 150., 151., 154., 155.],
- [ 140., 141., 144., 145., 156., 157., 160., 161.],
- [ 142., 143., 146., 147., 158., 159., 162., 163.]])
- In [121]: a[::-1]
- Out[121]:
- array([[ 142., 143., 146., 147., 158., 159., 162., 163.],
- [ 140., 141., 144., 145., 156., 157., 160., 161.],
- [ 134., 135., 138., 139., 150., 151., 154., 155.],
- [ 132., 133., 136., 137., 148., 149., 152., 153.],
- [ 110., 111., 114., 115., 126., 127., 130., 131.],
- [ 108., 109., 112., 113., 124., 125., 128., 129.],
- [ 102., 103., 106., 107., 118., 119., 122., 123.],
- [ 100., 101., 104., 105., 116., 117., 120., 121.]])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement