NumPy Array to List Conversion
<p>In OpenCV 3 the function <code>goodFeaturesToTrack</code> returns an array of the following form</p>

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

<p>After converting that array into a Python list I get </p>

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

<p>Although this is a list, if you see it has one more pair of brackets than it should and when I try to access an element via A[0][1] I get an error. Why the array and the list have that form? How should I fix it?</p>

<p>Because you have a 3d array with one element in second axis:</p>

<pre><code>In [26]: A = [[[1, 2]], [[3, 4]], [[5, 6]], [[7, 8]]]

In [27]: A[0]
Out[27]: [[1, 2]]
</code></pre>

<p>And when you want to access the second item by <code>A[0][1]</code> it raises an IndexError:</p>

<pre><code>In [28]: A[0][1]
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
&lt;ipython-input-28-99c47bb3f368&gt; in &lt;module&gt;()
----&gt; 1 A[0][1]

IndexError: list index out of range
</code></pre>

<p>You can use <code>np.squeeze()</code> in order to reduce the dimension, and convert the array to a 2D array: </p>

<pre><code>In [21]: import numpy as np

In [22]: A = np.array([[[1, 2]], [[3, 4]], [[5, 6]], [[7, 8]]])

In [33]: A = np.squeeze(A)

In [34]: A
Out[34]: 
array([[1, 2],
       [3, 4],
       [5, 6],
       [7, 8]])
</code></pre>

python python-3.x opencv