How could one map a a list of ndarrays containing string objects into specific floats ? For instance, if the user decides to map orange to 1.0 and grapefruit to 2.0 ?
myList = [np.array([['orange'], ['orange'], ['grapefruit']], dtype=object), np.array([['orange'], ['grapefruit'], ['orange']], dtype=object)]
So one would have:
convList = [np.array([['1.0'], ['1.0'], ['2.0']], dtype=float), np.array([['1.0'], ['2.0'], ['1.0']], dtype=float)]
I tried to implement this function:
def map_str_to_float(iterator):
d = {}
for ndarr in iterator:
for string_ in ndarr:
d[string_] = float(input('Enter your map for {}: '.format(string_)))
return d
test = map_str_to_float(myList)
print(test)
But I get the following error:
d[string_] = float(input('Enter your map for {}: '.format(string_)))
TypeError: unhashable type: 'numpy.ndarray'
I believe it's because the type of string_ is a numpy array instead of a string...