<p dir="auto">My issue concerns <code class="notranslate">scipy.sparse.csgraph.shortest_path</code>, more specifically the Floyd-Warshall solver, which does not deal with <strong>explicit zeros</strong> as the other algorithms (they are removed <a href="https://github.com/scipy/scipy/blob/master/scipy/sparse/csgraph/_shortest_path.pyx#L343">here</a>).</p>
<p dir="auto">The following (slightly convoluted) example highlights the different handling of explicit zeros.</p>
<h4 dir="auto">Reproducing code example:</h4>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import numpy as np
import scipy.sparse.csgraph
import sklearn.neighbors

examples = [
    # no infinity
    # (the undirected graph has one connected component)
    np.array([0, 1, 2, 3, 3])[:, None],
    # infinity only for 'FW' solver
    # (the undirected graph has one connected component)
    np.array([0, 1, 2, 3, 3, 3])[:, None],
    # infinity for all solvers
    # (the undirected graph has two connected components)
    np.array([0, 1, 2, 4, 4, 4])[:, None],
]

for X in examples:
    graph = sklearn.neighbors.kneighbors_graph(X, n_neighbors=2,
                                               mode='distance')
    print(scipy.sparse.csgraph.connected_components(graph)[0], end='\t')

    for method in ['FW', 'D', 'BF', 'J']:
        paths = scipy.sparse.csgraph.shortest_path(graph, method=method,
                                                   directed=False)
        print(np.any(np.isinf(paths)), end='\t')

    print('')"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">numpy</span> <span class="pl-k">as</span> <span class="pl-s1">np</span>
<span class="pl-k">import</span> <span class="pl-s1">scipy</span>.<span class="pl-s1">sparse</span>.<span class="pl-s1">csgraph</span>
<span class="pl-k">import</span> <span class="pl-s1">sklearn</span>.<span class="pl-s1">neighbors</span>

<span class="pl-s1">examples</span> <span class="pl-c1">=</span> [
    <span class="pl-c"># no infinity</span>
    <span class="pl-c"># (the undirected graph has one connected component)</span>
    <span class="pl-s1">np</span>.<span class="pl-en">array</span>([<span class="pl-c1">0</span>, <span class="pl-c1">1</span>, <span class="pl-c1">2</span>, <span class="pl-c1">3</span>, <span class="pl-c1">3</span>])[:, <span class="pl-c1">None</span>],
    <span class="pl-c"># infinity only for 'FW' solver</span>
    <span class="pl-c"># (the undirected graph has one connected component)</span>
    <span class="pl-s1">np</span>.<span class="pl-en">array</span>([<span class="pl-c1">0</span>, <span class="pl-c1">1</span>, <span class="pl-c1">2</span>, <span class="pl-c1">3</span>, <span class="pl-c1">3</span>, <span class="pl-c1">3</span>])[:, <span class="pl-c1">None</span>],
    <span class="pl-c"># infinity for all solvers</span>
    <span class="pl-c"># (the undirected graph has two connected components)</span>
    <span class="pl-s1">np</span>.<span class="pl-en">array</span>([<span class="pl-c1">0</span>, <span class="pl-c1">1</span>, <span class="pl-c1">2</span>, <span class="pl-c1">4</span>, <span class="pl-c1">4</span>, <span class="pl-c1">4</span>])[:, <span class="pl-c1">None</span>],
]

<span class="pl-k">for</span> <span class="pl-v">X</span> <span class="pl-c1">in</span> <span class="pl-s1">examples</span>:
    <span class="pl-s1">graph</span> <span class="pl-c1">=</span> <span class="pl-s1">sklearn</span>.<span class="pl-s1">neighbors</span>.<span class="pl-en">kneighbors_graph</span>(<span class="pl-v">X</span>, <span class="pl-s1">n_neighbors</span><span class="pl-c1">=</span><span class="pl-c1">2</span>,
                                               <span class="pl-s1">mode</span><span class="pl-c1">=</span><span class="pl-s">'distance'</span>)
    <span class="pl-en">print</span>(<span class="pl-s1">scipy</span>.<span class="pl-s1">sparse</span>.<span class="pl-s1">csgraph</span>.<span class="pl-en">connected_components</span>(<span class="pl-s1">graph</span>)[<span class="pl-c1">0</span>], <span class="pl-s1">end</span><span class="pl-c1">=</span><span class="pl-s">'<span class="pl-cce">\t</span>'</span>)

    <span class="pl-k">for</span> <span class="pl-s1">method</span> <span class="pl-c1">in</span> [<span class="pl-s">'FW'</span>, <span class="pl-s">'D'</span>, <span class="pl-s">'BF'</span>, <span class="pl-s">'J'</span>]:
        <span class="pl-s1">paths</span> <span class="pl-c1">=</span> <span class="pl-s1">scipy</span>.<span class="pl-s1">sparse</span>.<span class="pl-s1">csgraph</span>.<span class="pl-en">shortest_path</span>(<span class="pl-s1">graph</span>, <span class="pl-s1">method</span><span class="pl-c1">=</span><span class="pl-s1">method</span>,
                                                   <span class="pl-s1">directed</span><span class="pl-c1">=</span><span class="pl-c1">False</span>)
        <span class="pl-en">print</span>(<span class="pl-s1">np</span>.<span class="pl-en">any</span>(<span class="pl-s1">np</span>.<span class="pl-en">isinf</span>(<span class="pl-s1">paths</span>)), <span class="pl-s1">end</span><span class="pl-c1">=</span><span class="pl-s">'<span class="pl-cce">\t</span>'</span>)

    <span class="pl-en">print</span>(<span class="pl-s">''</span>)</pre></div>
<h4 dir="auto">Print message:</h4>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="1	False	False	False	False	
1	True	False	False	False	
2	True	True	True	True"><pre class="notranslate"><code class="notranslate">1	False	False	False	False	
1	True	False	False	False	
2	True	True	True	True
</code></pre></div>
<h4 dir="auto">Explanations:</h4>
<p dir="auto">Explicit zeros arise when you have duplicate points in your graph, thus having a connection with a distance of zero, which is different from the implicit zero (meaning no graph connection). When building a k-nearest neighbors graph, if some points are duplicated <strong>more</strong> than the number of neighbors k, then these points have <strong>only</strong> zeros in the set of explicit values, and using explicit zeros as if they were implicit zeros effectively remove the points from the connected graph. In particular, these points may still be connected to the rest if they are chosen as neighbors of another point (with <code class="notranslate">directed=False</code>).</p>
<h4 dir="auto">Scipy/Numpy/Python version information:</h4>

<p dir="auto">1.2.1 1.16.4 sys.version_info(major=3, minor=7, micro=3, releaselevel='final', serial=0)</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="In [5]: from scipy.stats import multivariate_normal

In [7]: multivariate_normal().rvs(size=(1,)).shape
Out[7]: ()"><pre class="notranslate"><code class="notranslate">In [5]: from scipy.stats import multivariate_normal

In [7]: multivariate_normal().rvs(size=(1,)).shape
Out[7]: ()
</code></pre></div>
<p dir="auto">All size parameters should support <code class="notranslate">None</code>, <code class="notranslate">()</code> and <code class="notranslate">(1,)</code> and produce shapes <code class="notranslate">()</code>, <code class="notranslate">()</code>, and <code class="notranslate">(1,)</code> respectively.</p>
<p dir="auto">As mentioned below, this problem also occurs with the <code class="notranslate">wishart</code> and <code class="notranslate">invwishart</code> distribution .</p>