code: def product(*arrays):
      
      arrays = [np.asarray(x) for x in arrays]
      shape = (len(x) for x in arrays)
      dtype = arrays[0].dtype
  
      ix = np.indices(shape)
      ix = ix.reshape(len(arrays), -1).T
  
      out = np.empty_like(ix, dtype=dtype)
  
      for n, _ in enumerate(arrays):
          out[:, n] = arrays[n][ix[:, n]]
  
      return out
docs: Generate a cartesian product of input arrays.
  
      Parameters
      ----------
      arrays : list of array-like
          1-D arrays to form the cartesian product of.
  
      Returns
      -------
      out : ndarray
          2-D array of shape (M, len(arrays)) containing cartesian products
          formed of input arrays.