Python: How to convert Numpy array item value type to array with this value?
<p>What is the best way to convert such ndarray:</p>

<pre><code>[[1,2,3], [4,5,6]]
</code></pre>

<p>to the:</p>

<pre><code>[[[1],[2],[3]], [[4],[5],[6]]]
</code></pre>

<p>just wrap each value to array</p>

<p>You can introduce a new axis with <a href="http://docs.scipy.org/doc/numpy-1.10.1/reference/arrays.indexing.html#numpy.newaxis" rel="nofollow"><code>np.newaxis/None</code></a> at the end, like so -</p>

<pre><code>arr[...,None]
</code></pre>

<p>Sample run -</p>

<pre><code>In [6]: arr = np.array([[1,2,3], [4,5,6]])

In [7]: arr[...,None]
Out[7]: 
array([[[1],
        [2],
        [3]],

       [[4],
        [5],
        [6]]])

In [8]: arr[...,None].tolist() # To show it as a list for expected o/p format
Out[8]: [[[1], [2], [3]], [[4], [5], [6]]]
</code></pre>

python arrays numpy