code: def khatrirao(A, reverse=False):
      
  
      if not isinstance(A, tuple):
          raise ValueError('A must be a tuple of array likes')
      N = A[0].shape[1]
      M = 1
      for i in range(len(A)):
          if A[i].ndim != 2:
              raise ValueError('A must be a tuple of matrices (A[%d].ndim = %d)' % (i, A[i].ndim))
          elif N != A[i].shape[1]:
              raise ValueError('All matrices must have same number of columns')
          M *= A[i].shape[0]
      matorder = arange(len(A))
      if reverse:
          matorder = matorder[::-1]
      # preallocate
      P = np.zeros((M, N), dtype=A[0].dtype)
      for n in range(N):
          ab = A[matorder[0]][:, n]
          for j in range(1, len(matorder)):
              ab = np.kron(ab, A[matorder[j]][:, n])
          P[:, n] = ab
      return P
docs: Compute the columnwise Khatri-Rao product.
  
      Parameters
      ----------
      A : tuple of ndarrays
          Matrices for which the columnwise Khatri-Rao product should be computed
  
      reverse : boolean
          Compute Khatri-Rao product in reverse order
  
      Examples
      --------
      >>> A = np.random.randn(5, 2)
      >>> B = np.random.randn(4, 2)
      >>> C = khatrirao((A, B))
      >>> C.shape
      (20, 2)
      >>> (C[:, 0] == np.kron(A[:, 0], B[:, 0])).all()
      true
      >>> (C[:, 1] == np.kron(A[:, 1], B[:, 1])).all()
      true