Search code examples
pythonnumpypsychopy

Can't access elements from an image array using python/psychopy/numpy


Using Python/Psychopy/numpy I have created an array containing 6 different sets of images. I am trying to display an image by accessing elements of the array. It is my understanding that [0][0] (I have also tried [0,0]) will access the first image from set 1, but I am getting the following error message:

AttributeError: 'numpy.ndarray' object has no attribute 'draw'

Here is my code, any help would be appreciated.

imgList1 = glob.glob(os.path.join('C:\Users\Steve\Desktop\stim','*.png')) 

set1 = [visual.ImageStim(window, img) for img in imgList1[:5]] #group stims into smaller lists
set2 = [visual.ImageStim(window, img) for img in imgList1[5:10]]
set3 = [visual.ImageStim(window, img) for img in imgList1[10:17]]
set4 = [visual.ImageStim(window, img) for img in imgList1[17:23]]
set5 = [visual.ImageStim(window, img) for img in imgList1[23:29]]
set6 = [visual.ImageStim(window, img) for img in imgList1[29:35]]

array1 = numpy.array([[set1],[set2],[set3],[set4],[set5],[set6]]) 

running = True
while running:
    array1[0][0].draw()
    window.flip()
    core.wait(1)

    window.close()

Cheers S


Solution

  • This is only logic.

    • array1 is the numpy array
    • array[0] is actually [set1]
    • array[0][0] is set1 -> a numpy array

    So you need to change your array1 declaration this way :

    array1 = numpy.array([set1,set2,set3,set4,set5,set6])