Numba with Dicts & np.zeros


I’m new to numba, but excited by what I’ve read about it so far.

I’ve got a function like this:

import numba
from numba import jit, types
from numba.typed import Dict

def metrics_from_matrix(confusion_matrix):
zero_matrix = np.zeros(confusion_matrix.shape, dtype=numba.int32)
metrics = Dict.empty(

I get a ‘non-precise type array(pyobject,1d,C)’ error on the “zero_matrix” line, and if I comment that out, on the “metrics = Dict” line as well. The full example is here:

Any ideas on how to fix this?

thank you

this means that there’s an array that contains python objects, instead of a dtype like integer or float. Probably the labels variable which seems to be strings coming from a dataframe. Numba cannot handle arrays of object type.
you could try converting that array to a typed.List