Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Python help

  • 18-03-2017 12:43pm
    #1
    Registered Users, Registered Users 2 Posts: 141 ✭✭


    I am new to Python and have to use it for a college assignment.

    I am trying to execute a section of code that will import a jpg image using PIL module and convert it to a numpy array.

    I keep getting the issue of "IndexError: too many indices for array"

    Been looking around on-line on how to fix this but none the wiser.

    import numpy as np
    import matplotlib.pylab as pyp

    from PIL import Image
    empire = np.array(Image.open('./empire.jpg'))
    print empire.shape, empire.dtype
    print empire [:2,:2]

    pyp.figure('Empire State Building')
    pyp.imshow(empire)
    pyp.show()

    IndexError Traceback (most recent call last)
    <ipython-input-4-391414696018> in <module>()
    6 empire = np.array(Image.open('./empire.jpg'))
    7 print empire.shape, empire.dtype
    ----> 8 print empire [:2,:2]
    9
    10 pyp.figure('Empire State Building')

    IndexError: too many indices for array


Comments

  • Registered Users, Registered Users 2 Posts: 7,157 ✭✭✭srsly78


    Look at the shape of the array.

    print empire.shape

    Run the code interactively (via notebook or debugger) so you can see what is happening.


Advertisement