[SciPy-User] Possible to access value in a Two-dimensional recorded array ?

Jonathan Helmus jjhelmus@gmail....
Tue Apr 23 09:28:55 CDT 2013


Troels,

     "dat1" is a value within the record array so you would need to find 
the index of the rows with that value.  You can use np.where or just use 
ndarray's built in fancy boolean indexing.  For example:

In [24]: cat example.txt
# an example table
aaa     1       1.234
bbb     2       5.678
ccc     3       9.012

In [25]: a = np.recfromtxt('example.txt', names="foo, bar, baz")

In [26]: a
Out[26]:
rec.array([('aaa', 1, 1.234), ('bbb', 2, 5.678), ('ccc', 3, 9.012)],
       dtype=[('foo', '|S3'), ('bar', '<i8'), ('baz', '<f8')])

In [27]: a[np.where(a['foo'] == 'aaa')]
Out[27]:
rec.array([('aaa', 1, 1.234)],
       dtype=[('foo', '|S3'), ('bar', '<i8'), ('baz', '<f8')])

In [28]: a[a.foo == 'aaa']
Out[28]:
rec.array([('aaa', 1, 1.234)],
       dtype=[('foo', '|S3'), ('bar', '<i8'), ('baz', '<f8')])

Cheers,

     - Jonathan Helmus


On 04/22/2013 11:47 AM, Troels Emtekær Linnet wrote:
> Hi.
>
> Does there exist a numpy recorded array, too access values row keys,
> so you can combine row and column keys?
> Now I am making a search for the value, but I guess that could be smarter?
>
>
> -----------------------
> import os
> import numpy as np
>
> os.chdir("C:/Users/tlinnet/Desktop")
>
> # data.txt
> #dat1 ../0plane.proc/test.ft2 peaks.list 0.06 28 466.667
> #dat2 ../1plane.proc/test.ft2 peaks.list 0.06 0 0.000
>
> fl = np.recfromtxt("data.txt", names="name, ftfile, peakfile, timeT2, 
> NI, nu")
> print fl['ftfile']
> print fl[1]['name']
> print fl[0]
> #print fl['dat1'] # ValueError: field named dat1 not found.
> l = 'dat2'
> s = np.where(l==fl['name'])
> print fl[s]['NI']
>
>
> Troels Emtekær Linnet
> Ved kløvermarken 9, 1.th <http://1.th>
> 2300 København S
> Mobil: +45 60210234 <tel:%2B45%2060210234>
>
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20130423/02befa19/attachment.html 


More information about the SciPy-User mailing list