I have a numpy array that is built with coded sections. The sections come in 2x2 blocks. I have a large dictionary of what those 2x2 blocks should be replaced with. How do I replace those 2x2 codes with values in the dictionary.
info_dict = {
5: np.array([[1, 0], [1, 0]], "int"),
6: np.array([[1, 0], [0, 1]], "int"),
7: np.array([[0, 1], [1, 0]], "int"),
8: np.array([[1, 1], [0, 0]], "int"),
}
print(np.array([[5, 5, 8, 8], [5, 5, 8, 8], [6, 6, 7, 7], [6, 6, 7, 7]]))
print(np.array([[1, 0, 1, 1], [1, 0, 0, 0], [1, 0, 0, 1], [0, 1, 1, 0]]))
# before (coded)
[[5 5 8 8]
[5 5 8 8]
[6 6 7 7]
[6 6 7 7]]
# after (final matrix)
[[1 0 1 1]
[1 0 0 0]
[1 0 0 1]
[0 1 1 0]]
For reference
#5
[[1 0]
[1 0]]
#6
[[1 0]
[0 1]]
#7
[[0 1]
[1 0]]
#8
[[1 1]
[0 0]]