[SciPy-User] Extracting float vector from tuple vector

josef.pktd@gmai... josef.pktd@gmai...
Mon Oct 26 17:19:35 CDT 2009


On Mon, Oct 26, 2009 at 6:15 PM, Joe Kington <jkington@wisc.edu> wrote:
> Maybe I'm confused here, but doesn't "results['score']" give you what you
> need?
> On Mon, Oct 26, 2009 at 5:08 PM, Ian Stokes-Rees
> <ijstokes@crystal.harvard.edu> wrote:
>>
>> Take 3 at sending this:
>>
>> > I have a vector that is defined as follows:
>> >
>> >    dtype   = [("score", "f4"), ("rfac", "f4"), ("codefull", "a10"),
>> > ("code2", "a2"), ("subset","a4"), ("source","a10")]
>> >    results = np.zeros((entry_count,), dtype=dtype)
>> >
>> > What I'd love to be able to do is to refer to a "slice" taken from a
>> > selection of rows, and only one tuple entry, e.g.:
>> >
>> > results[:]["score"]
>> >
>> > would return a vector of "f4" floats only, from the first entry of
>> > every tuple in results.
>> >
>> > I can't figure out how to do this!
>> >
>> > Any suggestions gratefully received.
>>
>>

>>> results[2:5]["score"]
array([ 2.,  3.,  4.], dtype=float32)
>>> results["score"][2:5]
array([ 2.,  3.,  4.], dtype=float32)

Josef

>>
>> _______________________________________________
>> SciPy-User mailing list
>> SciPy-User@scipy.org
>> http://mail.scipy.org/mailman/listinfo/scipy-user
>
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
>


More information about the SciPy-User mailing list