Forum: Ruby NArray help

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Joe L. (Guest)
on 2008-10-16 23:32
Hi,

 Could someone please tell me how the syntax works for the narray, max
and min methods.

 if i use @values.max i get the max of the entire array, after reading
the narray documentation http://narray.rubyforge.org/SPEC.en it looks
like i can get the max of a particular dimension at an orthogonal index,
however, i am at a loss to work out how this should be specified
syntatically.

 to put it another way, i have a 2D array, and i would like to find the
max and the min, of each of the columns 1..n.

Cheers

Joe
Joel VanderWerf (Guest)
on 2008-10-16 23:40
(Received via mailing list)
Joe Lovick wrote:
>
>  to put it another way, i have a 2D array, and i would like to find the
> max and the min, of each of the columns 1..n.

This maybe?

irb(main):006:0> a = NArray[ [1,2,3], [4,5,6] ]
=> NArray.int(3,2):
[ [ 1, 2, 3 ],
   [ 4, 5, 6 ] ]
irb(main):007:0> a.max(0)
=> NArray.int(2):
[ 3, 6 ]
irb(main):008:0> a.max(1)
=> NArray.int(3):
[ 4, 5, 6 ]

So I guess 0 means "max over each row", and 1 means "max over each
column".
Joe L. (Guest)
on 2008-10-16 23:55
> This maybe?
>
> irb(main):006:0> a = NArray[ [1,2,3], [4,5,6] ]
> => NArray.int(3,2):
> [ [ 1, 2, 3 ],
>    [ 4, 5, 6 ] ]
> irb(main):007:0> a.max(0)
> => NArray.int(2):
> [ 3, 6 ]
> irb(main):008:0> a.max(1)
> => NArray.int(3):
> [ 4, 5, 6 ]
>
> So I guess 0 means "max over each row", and 1 means "max over each
> column".

Thanks,

 my own stupidity even takes me by surprise

Cheers
 Joe
This topic is locked and can not be replied to.