擅长:python、mysql、java
<pre><code>In [121]: a1.dtype, a1.shape
Out[121]: (dtype('int32'), (5, 5, 2))
In [122]: c1 = np.array([a1,b1])
In [123]: c1.dtype, c1.shape
Out[123]: (dtype('O'), (2,))
</code></pre>
<p>因为<code>a1</code>和{<cd2>}是不同形状的对象(<code>b1</code>甚至不是数组),因此由它们组成的数组将具有dtype对象。而由几个组成的<code>h</code>仍然是object-dtype。在</p>
^{pr2}$
<p>在appends之后,<code>h</code>(作为数组)是object dtype。第2列是b1和b2值,第1列是a1和a2。在</p>
<p>要将这些<code>a1</code><code>a2</code>数组组合成一个数组,需要某种形式的连接。<code>stack</code>在一个新的轴上执行。在</p>
<pre><code>In [128]: h[0,0].shape
Out[128]: (5, 5, 2)
In [129]: np.array(h[:,0]).shape # np.array doesn't cross the object boundary
Out[129]: (2,)
In [130]: np.stack(h[:,0]).shape
Out[130]: (2, 5, 5, 2)
In [131]: np.concatenate(h[:,0],0).shape
Out[131]: (10, 5, 2)
</code></pre>
<p>将(2,)数组转换为一个列表,确实允许<code>np.array</code>将元素重新组合成一个更高维的数组,就像<code>np.stack</code>一样:</p>
<pre><code>In [133]: np.array(list(h[:,0])).shape
Out[133]: (2, 5, 5, 2)
</code></pre>