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 do it by recursively exploring the list of lists:</p>

<pre><code>def wrap_values(list_of_lists):
    if isinstance(list_of_lists, list):
        return [wrap_values(el) for _,el in enumerate(list_of_lists)]
    else:
        return [list_of_lists]


xx = [[1,2,3], [4,5,6]]
yy = wrap_values(xx)   # [[[1], [2], [3]], [[4], [5], [6]]]
</code></pre>

python arrays numpy