<p dir="auto">When passing tuple of ndarrays to np.asanyarray, it may return array of arrays OR give ValueError when first dimensions of arrays match. Found out trying to np.save a tuple (sometimes worked, sometimes did not).</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="np.__version__
'1.11.2'

a = np.ones((2,1))
b = np.ones(3)
np.asanyarray((a,b))
array([array([[ 1.],
       [ 1.]]), array([ 1.,  1.,  1.])], dtype=object)

b = b[:-1] # now the first dimensions match
np.asanyarray((a,b))
Traceback (most recent call last):
  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;
  File &quot;/Users/ml/anaconda/envs/face_lasagne/lib/python2.7/site-packages/numpy/core/numeric.py&quot;, line 533, in asanyarray
    return array(a, dtype, copy=False, order=order, subok=True)
ValueError: could not broadcast input array from shape (2,1) into shape (2)"><pre class="notranslate"><span class="pl-s1">np</span>.<span class="pl-s1">__version__</span>
<span class="pl-s">'1.11.2'</span>

<span class="pl-s1">a</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">ones</span>((<span class="pl-c1">2</span>,<span class="pl-c1">1</span>))
<span class="pl-s1">b</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">ones</span>(<span class="pl-c1">3</span>)
<span class="pl-s1">np</span>.<span class="pl-en">asanyarray</span>((<span class="pl-s1">a</span>,<span class="pl-s1">b</span>))
<span class="pl-en">array</span>([<span class="pl-en">array</span>([[ <span class="pl-c1">1.</span>],
       [ <span class="pl-c1">1.</span>]]), <span class="pl-en">array</span>([ <span class="pl-c1">1.</span>,  <span class="pl-c1">1.</span>,  <span class="pl-c1">1.</span>])], <span class="pl-s1">dtype</span><span class="pl-c1">=</span><span class="pl-s1">object</span>)

<span class="pl-s1">b</span> <span class="pl-c1">=</span> <span class="pl-s1">b</span>[:<span class="pl-c1">-</span><span class="pl-c1">1</span>] <span class="pl-c"># now the first dimensions match</span>
<span class="pl-s1">np</span>.<span class="pl-en">asanyarray</span>((<span class="pl-s1">a</span>,<span class="pl-s1">b</span>))
<span class="pl-v">Traceback</span> (<span class="pl-s1">most</span> <span class="pl-s1">recent</span> <span class="pl-s1">call</span> <span class="pl-s1">last</span>):
  <span class="pl-v">File</span> <span class="pl-s">"&lt;stdin&gt;"</span>, <span class="pl-s1">line</span> <span class="pl-c1">1</span>, <span class="pl-s1">in</span> <span class="pl-c1">&lt;</span><span class="pl-s1">module</span><span class="pl-c1">&gt;</span>
  <span class="pl-v">File</span> <span class="pl-s">"/Users/ml/anaconda/envs/face_lasagne/lib/python2.7/site-packages/numpy/core/numeric.py"</span>, <span class="pl-s1">line</span> <span class="pl-c1">533</span>, <span class="pl-s1">in</span> <span class="pl-s1">asanyarray</span>
    <span class="pl-k">return</span> <span class="pl-en">array</span>(<span class="pl-s1">a</span>, <span class="pl-s1">dtype</span>, <span class="pl-s1">copy</span><span class="pl-c1">=</span><span class="pl-c1">False</span>, <span class="pl-s1">order</span><span class="pl-c1">=</span><span class="pl-s1">order</span>, <span class="pl-s1">subok</span><span class="pl-c1">=</span><span class="pl-c1">True</span>)
<span class="pl-v">ValueError</span>: <span class="pl-s1">could</span> <span class="pl-c1">not</span> <span class="pl-s1">broadcast</span> <span class="pl-s1">input</span> <span class="pl-s1">array</span> <span class="pl-k">from</span> <span class="pl-en">shape</span> (<span class="pl-c1">2</span>,<span class="pl-c1">1</span>) <span class="pl-s1">into</span> <span class="pl-en">shape</span> (<span class="pl-c1">2</span>)</pre></div>
<p dir="auto">The functions numpy.array and numpy.asarray have a well defined behaviour when applied to lists of arrays: if the listed arrays have the same dimensions and size, the list is turned in one of the dimensions of the resulting array (let's call it "mode 1"). If not, an array of arrays is returned ("mode 2").</p>
<p dir="auto">However, the behaviour of numpy.array and numpy.asarray in "mode 2" seems to be dependent on the number of items in the arrays. The following code is not very elegant relative to numpy usefulness, but works:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; a = np.array([1, 2, 3])
&gt;&gt;&gt; b = np.array([[1, 0], [0, 1]])
&gt;&gt;&gt; np.asarray([a, b])
array([array([1, 2, 3]), array([[1, 0],
       [0, 1]])], dtype=object)"><pre class="notranslate"><code class="notranslate">&gt;&gt;&gt; a = np.array([1, 2, 3])
&gt;&gt;&gt; b = np.array([[1, 0], [0, 1]])
&gt;&gt;&gt; np.asarray([a, b])
array([array([1, 2, 3]), array([[1, 0],
       [0, 1]])], dtype=object)
</code></pre></div>
<p dir="auto">But the following doesn't:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; a = np.array([1, 2])
&gt;&gt;&gt; b = np.array([[1, 0], [0, 1]])
&gt;&gt;&gt; np.asarray([a, b])
Traceback (most recent call last):
  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;
  File &quot;/usr/local/lib/python3.4/dist-packages/numpy/core/numeric.py&quot;, line 474, in asarray
    return array(a, dtype, copy=False, order=order)
ValueError: could not broadcast input array from shape (2,2) into shape (2)"><pre class="notranslate"><code class="notranslate">&gt;&gt;&gt; a = np.array([1, 2])
&gt;&gt;&gt; b = np.array([[1, 0], [0, 1]])
&gt;&gt;&gt; np.asarray([a, b])
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  File "/usr/local/lib/python3.4/dist-packages/numpy/core/numeric.py", line 474, in asarray
    return array(a, dtype, copy=False, order=order)
ValueError: could not broadcast input array from shape (2,2) into shape (2)
</code></pre></div>
<p dir="auto">Clearly, the problem is that, when numpy.asarray sees the first dimension has the same length in <code class="notranslate">a</code> and <code class="notranslate">b</code>, it tries to go for "mode 1", which is impossible here.</p>
<p dir="auto">EDIT: I'm using numpy 1.10.4 and python 3.4.3.</p>