Error for a code to generate Cartesian product

I’m facing error while trying to run this piece of code:

import numpy as np
from numba import njit

@njit
def cartesian_product(*arrays):
“”"
A generator function that generates the Cartesian product of multiple arrays.
“”"
# Generate the meshgrid
grids = np.meshgrid(*arrays, indexing=‘ij’)

# Stack the arrays together to form the Cartesian product
stacked = np.stack([grid.ravel() for grid in grids], axis=-1)

# Yield each element of the Cartesian product
for elem in stacked:
    yield tuple(elem)

############################

Example usage

a = np.array([1, 2, 3])
b = np.array([4, 5])
c = np.array([6, 7, 8])

for elem in cartesian_product(a, b, c):
print(elem)
#################Error !!!#################################3
File “C:\Users\XYZ\Anaconda3\lib\site-packages\numba\dataflow.py”, line 358, in op_CALL_FUNCTION_EX
raise NotImplementedError(errmsg)

NotImplementedError: Failed in nopython mode pipeline (step: analyzing bytecode)
CALL_FUNCTION_EX with **kwargs not supported

Win7, Python 3.7, numpy 1.16.5

The error mentions that something you’re using isn’t implemented. Looking through the supported numpy items I didn’t see any mention of np.meshgrid() so maybe that’s it.
You could try reducing the operations in your function to narrow down which one is causing the error, or perhaps someone else who knows for sure will respond here.

1 Like