indexing arrays

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John [H2O]

    indexing arrays


    I'm having trouble slicing arrays:

    I thought I could do the following:
    >>i = array(range(140 ,149))
    >>j = array(range(5,2 0))
    >>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-array...p19918073.html
    Sent from the Python - python-list mailing list archive at Nabble.com.

  • Emily Rodgers

    #2
    Re: indexing arrays


    "John [H2O]" <washakie@gmail .comwrote in message
    news:mailman.23 21.1223644314.3 487.python-list@python.org ...
    >
    I'm having trouble slicing arrays:
    >
    I thought I could do the following:
    >>>i = array(range(140 ,149))
    >>>j = array(range(5,2 0))
    >>>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?


    Comment

    • Jeremy Sanders

      #3
      Re: indexing arrays

      John [H2O] wrote:
      Anyone know what I am doing wrong?
      The arrays in the numpy package are more sophisticated than the built-in
      array package. This sort of thing works there:
      >>import numpy
      >>a = numpy.array([1,2,3,4,5,6,7,8])*2
      >>a
      array([ 2, 4, 6, 8, 10, 12, 14, 16])
      >>a[range(3,6)]
      array([ 8, 10, 12])

      Jeremy

      --
      Jeremy Sanders

      Comment

      Working...