create 2d array with lists as entries
<p>I want to create a 2d numpy array that contains python lists as entries.
The mainprogram will append IDs to each entry. In the end I need to search for the entry with the most appended IDs. I will need these IDs later on and because of this a simple 2d array with integer entries, that just get incremented, won't solve my problem.
So my question is:
How do I create a 2d numpy array that contains python lists as entries?</p>

<pre><code>import cv2
import numpy as np

#get image
image_rgb = cv2.imread('testpic.png')
#grayscale imgae
image = cv2.cvtColor(image_rgb, cv2.COLOR_BGR2GRAY)

#generate evalutatearray (2d array with list entrys)
evaluatelist = np.empty(image.shape)

ID = 443

evaluatelist[34,78].append(ID)
</code></pre>

<p>You can try to create an empty numpy array of object type and then assign lists to array entries, you have to adapt your code as such</p>

<pre><code>evaluatelist = np.empty(image.shape, dtype=object)
for x in xrange(evaluatelist.shape[0]):
    for y in xrange(evaluatelist.shape[1]):
        evaluatelist[x,y] = []
</code></pre>

<p>That is assuming that the array creation with image.shape works.</p>

python arrays list numpy