I have a dictionary composed of arrays of unequal length that looks like the following:
mydict = {'A': array([ 1, 5, 6, 10, 13, 17, 20, 22]), 'B': array([ 3, 8, 9, 15, 16]), 'C': array([ 0, 2, 4, 7, 11, 12, 14])}
I'm looking to retrieve the key for a given number (e.g. key for 22 being 'A'), but I'm guessing it's the multi-array structure of this dict that is producing an error when using previously posted solutions:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
Is there a straightforward way to connect the value to the key with this dict without transforming the array structure? Ultimately I'm trying to add the key of a value to a row with other associated data for export.
What I attempted based on previous answers:
res = dict((v, k) for k, v in mydict.items())
print(res[10])
I want it to print 'A' but it produces
TypeError: unhashable type: 'numpy.ndarray'