indexing question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Faheem Mitha

    indexing question

    Dear People,

    Suppose I create a numarray arry (say). A numeric array would be fine
    too; it probably does not matter.
    [color=blue][color=green][color=darkred]
    >>>import numarray
    >>>foo = numarray.reshap e(numarray.aran ge(9),(3,3))[/color][/color][/color]
    array([[ 0, 1, 2, 3],
    [ 4, 5, 6, 7],
    [ 8, 9, 10, 11],
    [12, 13, 14, 15]])

    Is there some way to select the indexes corresponding only to (say)
    two rows or columns?

    ie suppose I just want the first and the fourth row or the first and
    third columns? Is there some clean way to do this which does not
    involve extract individual rows or columns?

    Ie. I want something like[color=blue][color=green][color=darkred]
    >>> foo[?,:][/color][/color][/color]
    array([[ 0, 1, 2, 3],
    [12, 13, 14, 15]])

    etc.

    Suggestions appreciated. Thanks in advance.

    Faheem.
  • wes weston

    #2
    Re: indexing question

    Faheem Mitha wrote:[color=blue]
    > Dear People,
    >
    > Suppose I create a numarray arry (say). A numeric array would be fine
    > too; it probably does not matter.
    >
    >[color=green][color=darkred]
    >>>>import numarray
    >>>>foo = numarray.reshap e(numarray.aran ge(9),(3,3))[/color][/color]
    >
    > array([[ 0, 1, 2, 3],
    > [ 4, 5, 6, 7],
    > [ 8, 9, 10, 11],
    > [12, 13, 14, 15]])
    >
    > Is there some way to select the indexes corresponding only to (say)
    > two rows or columns?
    >
    > ie suppose I just want the first and the fourth row or the first and
    > third columns? Is there some clean way to do this which does not
    > involve extract individual rows or columns?
    >
    > Ie. I want something like
    >[color=green][color=darkred]
    >>>>foo[?,:][/color][/color]
    >
    > array([[ 0, 1, 2, 3],
    > [12, 13, 14, 15]])
    >
    > etc.
    >
    > Suggestions appreciated. Thanks in advance.
    >
    > Faheem.[/color]

    Faheem,
    On the following like, I see something like what you
    want.



    wes

    Comment

    • Faheem Mitha

      #3
      Re: indexing question

      On Fri, 26 Mar 2004 16:32:32 GMT, wes weston <wweston@att.ne t> wrote:
      [color=blue]
      > Faheem,
      > On the following like, I see something like what you
      > want.
      >
      > http://matpy.sourceforge.net/MatPy/node3.html[/color]

      Yes, I realise that I can take slices as long as the corresponding
      rows and columns are contiguous. My question is, how can I make a
      subarray from rows or columns that are *not* contiguous? If this is
      possible, can you show me an example?

      Faheem.

      Comment

      Working...