FAQ
I'm having trouble slicing arrays:

I thought I could do the following:
i = array(range(140,149))
j = array(range(5,20))
a = acc[i,j]
Traceback (most recent call last):
File "<string>", line 1, in <string>
ValueError: shape mismatch: objects cannot be broadcast to a single shape

It's strange, because I can do this:
a = acc[140:148,5:19]

Anyone know what I am doing wrong?

--
View this message in context: http://www.nabble.com/indexing-arrays-tp19918073p19918073.html
Sent from the Python - python-list mailing list archive at Nabble.com.

Search Discussions

  • Emily Rodgers at Oct 10, 2008 at 2:04 pm
    "John [H2O]" <washakie at gmail.com> wrote in message
    news:mailman.2321.1223644314.3487.python-list at python.org...
    I'm having trouble slicing arrays:

    I thought I could do the following:
    i = array(range(140,149))
    j = array(range(5,20))
    a = acc[i,j]
    Traceback (most recent call last):
    File "<string>", line 1, in <string>
    ValueError: shape mismatch: objects cannot be broadcast to a single shape

    It's strange, because I can do this:
    a = acc[140:148,5:19]

    Anyone know what I am doing wrong?
    What data structure is acc, and what are you trying to do?
  • Terry Reedy at Oct 10, 2008 at 9:17 pm

    John [H2O] wrote:
    I'm having trouble slicing arrays:
    If these are numpy arrays, as appears, rather that array module arrays,
    then the numpy list might be a better place. In any case, using 'numpy'
    would have gotten the attention of someone scanning for posts about numpy.
    I thought I could do the following:
    i = array(range(140,149))
    j = array(range(5,20))
    a = acc[i,j]
    Traceback (most recent call last):
    File "<string>", line 1, in <string>
    ValueError: shape mismatch: objects cannot be broadcast to a single shape

    It's strange, because I can do this:
    a = acc[140:148,5:19]

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedOct 10, '08 at 1:11p
activeOct 10, '08 at 9:17p
posts3
users3
websitepython.org

People

Translate

site design / logo © 2021 Grokbase