NArray help


#1

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


#2

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”.


#3

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