title: i want to compute the distance between two numpy histogram
body: <p>i'm creating an image processing program and i want to measure the wasserstein  distance between  two numpy histograms.
  the two histogram are created with the function <a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.histogram.html" rel="nofollow noreferrer">numpy.histogram</a></p>
  
  <p>i tried the wasserstein_distance from the scipy.stats package like this</p>
  
  <pre><code>from scipy.stats import wasserstein_distance 
  wasserstein_distance(histogram1,histogram2)
  </code></pre>
  
  <p>but it gives me that error</p>
  
  <blockquote>
    <p>ValueError: setting an array element with a sequence.</p>
  </blockquote>
  
  <p>the complete code:</p>
  
  <p>first the function that calculate the distance:</p>
  
  <pre><code>    def f_dist( histogram1 ,histogram2):
      return wasserstein_distance(histogram1,histogram2)
  </code></pre>
  
  <p>than the function that calculate the mask for the histograme creation:</p>
  
  <pre><code>def prepare_mask(polygon, image,value):
  """Returns binary mask based on input polygon presented as list of coordinates of vertices
  Params:
      polygon (list) - coordinates of polygon's vertices. Ex: [(x1,y1),(x2,y2),...] or [x1,y1,x2,y2,...]
      image (numpy array) - original image. Will be used to create mask of the same size. Shape (H, W, C).
  Output:
      mask (numpy array) - boolean mask. Shape (H, W).
  """
  # create an "empty" pre-mask with the same size as original image
  width = image.shape[1]
  height = image.shape[0]
  mask = Image.new('L', (width, height),value )
  # Draw your mask based on polygon
  ImageDraw.Draw(mask).polygon(polygon, outline=1, fill=abs(value-1))
  # Covert to np array
  mask = np.array(mask).astype(bool)
  return mask
  </code></pre>
  
  <p>than the function that creat the histogram</p>
  
  <pre><code>def compute_histogram(mask, image):
  """Returns histogram for image region defined by mask for each channel
  Params:
      image (numpy array) - original image. Shape (H, W, C).
      mask (numpy array) - boolean mask. Shape (H, W).
  Output:
      list of tuples, each tuple (each channel) contains 2 arrays: first - computed histogram, the second - bins.
  
  """
  # Apply binary mask to your array, you will get array with shape (N, C)
  region = image[mask]
  
  hist = np.histogram(region.ravel(), bins=256, range=[0, 255])
  
  return hist
  </code></pre>
  
  <p>and now for the main fnction:</p>
  
  <pre><code>points=[(633, 312), (630, 351), (623, 389), (611, 426), (594, 462), (573, 495), (548, 525), (519, 552), (488, 575), (453, 594), (417, 608), (379, 618), (340, 623), (301, 623), (262, 618), (224, 608), (188, 594), (153, 575), (122, 552), (93, 525), (68, 495), (47, 462), (30, 426), (18, 389), (11, 351), (9, 311), (11, 272), (18, 234), (30, 197), (47, 161), (68, 128), (93, 98), (122, 71), (153, 48), (188, 29), (224, 15), (262, 5), (301, 0), (340, 0), (379, 5), (417, 15), (453, 29), (488, 48), (519, 71), (548, 98), (573, 128), (594, 161), (611, 197), (623, 234), (630, 272)]
  mask1 = prepare_mask(points, image_gray, 0)
  mask2 = prepare_mask(points, image_gray, 1)
  histogram1 = compute_histogram(mask1, image_gray)
  histogram2 = compute_histogram(mask2, image_gray)
  dist=f_dist(histogram1,histogram2)
  </code></pre>