numpy and filtering (was: Fastest way to store ints and floats ondisk)

Discussion in 'Python' started by Laszlo Nagy, Aug 8, 2008.

  1. Laszlo Nagy

    Laszlo Nagy Guest

    Attached there is an example program that only requires numpy. At the
    end I have two numpy array:

    rdims:

    [[3 1 1]
    [0 0 4]
    [1 3 0]
    [2 2 0]
    [3 3 3]
    [0 0 2]]


    rmeas:

    [[100000.0 254.0]
    [40000.0 200.0]
    [50000.0 185.0]
    [5000.0 160.0]
    [150000.0 260.0]
    [20000.0 180.0]]


    I would like to use numpy to create statistic, for example the mean
    value of the prices:

    >>> rmeas[:,0] # Prices of cars

    array([100000.0, 40000.0, 50000.0, 5000.0, 150000.0, 20000.0],
    dtype=float96)
    >>> rmeas[:,0].mean() # Mean price

    60833.3333333333333321

    However, I only want to do this for 'color=yellow' or 'year=2003,
    make=Ford' etc. I wonder if there a built-in numpy method that can
    filter out rows using a set of values. E.g. create a view of the
    original array or a new array that contains only the filtered rows. I
    know how to do it from Python with iterators, but I wonder if there is a
    better way to do it in numpy. (I'm new to numpy please forgive me if
    this is a dumb question.)

    Thanks,

    Laszlo
    Laszlo Nagy, Aug 8, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chris
    Replies:
    5
    Views:
    396
    Randolf Richardson
    Jan 28, 2007
  2. Skybuck Flying

    ints ints ints and ints

    Skybuck Flying, Jul 8, 2004, in forum: C Programming
    Replies:
    24
    Views:
    820
    Jack Klein
    Jul 10, 2004
  3. Laszlo Nagy
    Replies:
    2
    Views:
    263
    Matthew Woodcraft
    Aug 9, 2008
  4. M.-A. Lemburg
    Replies:
    3
    Views:
    270
    castironpi
    Aug 10, 2008
  5. castironpi
    Replies:
    5
    Views:
    333
    castironpi
    Aug 24, 2008
Loading...

Share This Page