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
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
From: [email protected]
Subject: Re: Multidimensional “.index” ?
Date: Fri, 23 Jun 2006 11:35:10 +0900
harp:~ > cat a.rb
p na[idx][ 0, 0, 0, 1 ] ]
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
On Fri, 23 Jun 2006, Meino Christian C. wrote:
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
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs