Look at your dicitonary:
In [21]: dd = dict(zip(numpy.arange(5), numpy.arange(5)*10))
In [22]: dd
Out[22]: {0: 0, 1: 10, 2: 20, 3: 30, 4: 40}
the keys are numbers. The same thing can be produced without numpy:
In [23]: dict(zip(range(5), range(0,50,10)))
Out[23]: {0: 0, 1: 10, 2: 20, 3: 30, 4: 40}
Your vectorize array access:
In [29]: y = np.vectorize(lambda x: dd[x], otypes=[int])
In [30]: y([0,1,3])
Out[30]: array([ 0, 10, 30])
In [31]: y([])
Out[31]: array([], dtype=int64)
I added the otypes so that the [] works.
I don't see why you want to add an entry that has an array key. None of the other keys are arrays. And as you found out an array can't be a key.
dictionary[np.array([], dtype='int64')]
vectorize passes scalar values from the argument to your function. It does not pass an array. So there's no point to having an array, empty or not, as a key.
Whether np.vectorize is the best tool for using this dictionary is another question. Usually it doesn't improve speed over iterative access. Using a dictionary might the underlying problem, since it can only be accessed on key at a time.
===
Without the otypes, vectorize raises an error
ValueError: cannot call `vectorize` on size 0 inputs unless `otypes` is set
vectorize makes a trial call to the function to determine the return dtype.
===
Here's a more robust version of your y, one that won't choke on a missing key:
In [32]: y = np.vectorize(lambda x: dd.get(x,-100), otypes=[int])
In [33]: y([1,2,3,10])
Out[33]: array([ 10, 20, 30, -100])
xto be an array (empty or not) when doingdict[x]. At most,xcan be an empty tuple.https://stackoverflow.com/a/7027308/12420884ValueError: cannot callvectorize` on size 0 inputs unlessotypesis set` if I attempt to just cally([]). It never gets to your function. If you pass in an array of numbers, your function will never get an empty array either.np.vectorizeis almost never the right answer.np.vectorize.