From: Meino Christian Cramer Date: 2006-06-23T11:44:14+09:00 Subject: Re: Multidimensional ".index" ? From: ara.t.howard@noaa.gov Subject: Re: Multidimensional ".index" ? Date: Fri, 23 Jun 2006 11:35:10 +0900 > On Fri, 23 Jun 2006, Meino Christian Cramer wrote: > > > Hi, > > > > a=[1,2,3,4] > > a.index(3) -> 2 > > > > Is there any way to do such things: > > > > a=[[1,2,3,4],[5,6,7,8],[9,10,11,12]] > > > > a.index(6) -> [1,1] > > > > > > may be for n-dimensional arrays, too ? > > > > Thank you very much for any helpful reply in advance ! > > > > Keep ruby! > > mcc > > harp:~ > cat a.rb > require 'narray' > > na = NArray.to_na [ > [1,2,3,4], > [5,6,7,8], > [9,10,11,12] > ] > > idx = na.eq 7 > p idx > p na[idx] > > idx = na.eq(7).or(na.eq(12)) > p idx > p na[idx] > > idx = na.gt 6 > p idx > p na[idx] > > > > harp:~ > ruby a.rb > NArray.byte(4,3): > [ [ 0, 0, 0, 0 ], > [ 0, 0, 1, 0 ], > [ 0, 0, 0, 0 ] ] > NArray.int(1): > [ 7 ] > NArray.byte(4,3): > [ [ 0, 0, 0, 0 ], > [ 0, 0, 1, 0 ], > [ 0, 0, 0, 1 ] ] > NArray.int(2): > [ 7, 12 ] > NArray.byte(4,3): > [ [ 0, 0, 0, 0 ], > [ 0, 0, 1, 1 ], > [ 1, 1, 1, 1 ] ] > NArray.int(6): > [ 7, 8, 9, 10, 11, 12 ] > > > and so much more. it's all on rubyforge. > > -a > -- > suffering increases your inner strength. also, the wishing for suffering > makes the suffering disappear. > - h.h. the 14th dali lama > THANK YOU! :)) Have a nice weekend! mcc