<p dir="auto">In Python3 not all objects are comparable:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; a = ['', 3, 5, 8, None]
&gt;&gt;&gt; a.sort()
Traceback (most recent call last):
  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;
TypeError: unorderable types: int() &lt; str()
&gt;&gt;&gt; a
['', 3, 5, 8, None]"><pre class="notranslate"><code class="notranslate">&gt;&gt;&gt; a = ['', 3, 5, 8, None]
&gt;&gt;&gt; a.sort()
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
TypeError: unorderable types: int() &lt; str()
&gt;&gt;&gt; a
['', 3, 5, 8, None]
</code></pre></div>
<p dir="auto">Numpy does not acknowledge this possibility, so when trying to sort an object array, even though the error is raised, the sorting goes on as if all unorderable objects compared equal:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; arr = np.array(a, dtype=object)
&gt;&gt;&gt; arr
array(['', 3, 5, 8, None], dtype=object)
&gt;&gt;&gt; arr.sort()
Traceback (most recent call last):
  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;
TypeError: unorderable types: int() &gt; NoneType()
&gt;&gt;&gt; arr
array([3, 5, 8, None, ''], dtype=object)"><pre class="notranslate"><code class="notranslate">&gt;&gt;&gt; arr = np.array(a, dtype=object)
&gt;&gt;&gt; arr
array(['', 3, 5, 8, None], dtype=object)
&gt;&gt;&gt; arr.sort()
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
TypeError: unorderable types: int() &gt; NoneType()
&gt;&gt;&gt; arr
array([3, 5, 8, None, ''], dtype=object)
</code></pre></div>
<p dir="auto">Using some set of parameters with <code class="notranslate">numpy.digitize</code> should yield the same bin classification as those from <code class="notranslate">numpy.histogram</code>.</p>
<p dir="auto">For instance given an array <code class="notranslate">x</code> I may have 10 bins (11 bin edges). If I pass any individual entry from the array to <code class="notranslate">numpy.digitize</code>:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import numpy 

counts,bin_edges = numpy.histogram(X,bins=10)
ind = numpy.digitize(x[i],bin_edges,right=True)"><pre class="notranslate"><code class="notranslate">import numpy 

counts,bin_edges = numpy.histogram(X,bins=10)
ind = numpy.digitize(x[i],bin_edges,right=True)
</code></pre></div>
<p dir="auto">For <code class="notranslate">x[i] &lt;= bin_edges[0]</code>  left edge cases and  <code class="notranslate">x[i] &gt;= bin_edges[-1]</code> right edge cases I will get <code class="notranslate">ind</code> as <code class="notranslate">0</code> or <code class="notranslate">bin_edges.shape[0]</code>, respectively. There should be a way to have the output agree with histogram without adding new binning.</p>
<p dir="auto">I currently add something like this to fix the bounding issue on the left edge case</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="fix = lambda x: 1 if x == 0 else x
ind = fix(ind)"><pre class="notranslate"><code class="notranslate">fix = lambda x: 1 if x == 0 else x
ind = fix(ind)
</code></pre></div>
<p dir="auto">For the right edge case use the <code class="notranslate">right=True</code> parameter and only pass <code class="notranslate">bin_edges[:-2]</code>.</p>