擅长:python、mysql、java
<p>所以,这就是我所做的。</p>
<pre><code>>>>n = np.matrix('1,2,3,4,5')
>>> n
matrix([[1, 2, 3, 4, 5]])
>>>np.insert(n,5,6)
matrix([[1, 2, 3, 4, 5, 6]])
</code></pre>
<p>对于多维数组,必须提到水平索引和垂直索引,否则生成的矩阵将被展平。</p>
<pre><code>>>> n = np.matrix('1,2;4,5')
>>> n
matrix([[1, 2],
[4, 5]])
>>> np.insert(n,1,6) #Here 1 indicates the index in the flattened matrix.
matrix([[1, 6, 2, 4, 5]])
</code></pre>
<p>在文档中,垂直索引被称为“轴”。</p>
<pre><code>>>> n = np.matrix('1,2;4,5')
>>> n
matrix([[1, 2],
[4, 5]])
>>> np.insert(n,1,6, axis=1)
matrix([[1, 6, 2],
[4, 6, 5]])
>>> np.insert(n,1,(67,78), axis=1)
matrix([[ 1, 67, 2],
[ 4, 78, 5]])
</code></pre>
<p><a href="http://docs.scipy.org/doc/numpy-1.10.0/reference/generated/numpy.insert.html" rel="nofollow">Here's</a>指向文档的链接。</p>