I'm using a (numpy) array of integers to log potential problems with an array of data. The concept is that each error type has its own integer value, and that these are set so that
err1 = 1
err2 = 2 ** 1
err3 = 2 ** 2
...
errx = 2 ** x
This way, I figure, I can add these error types to the integer logging array, and still know what combination of errors made up that value; so if the end array has a value of 7, I know it must have be made of up 1 + 2 + 4 - ie, err1, err2, and err3.
This all seemed very clever at the time, but I now need to produce a boolean array telling me which cells have logged a given error; so, for example, if I have an error array of
test_arr = np.array(
[[1, 5, 19],
[3, 4, 12]]
)
I'd like to get the result
test_contains_err3 = np.array(
[[False, True, False],
[False, True, True]]
)
Because the value 4 has gone into making up the values 5 and 4, but not any of the others. I've developed an iterative solution for single values, but that then doesn't work well for a vectorized calculation (the actual array is quite large). Can any one please suggest something? I have a feeling that there's something simpler here that I'm not seeing.
Thanks in advance!