NArray help

J

Joe Lovick

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
 
J

Joel VanderWerf

Joe said:
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.

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".
 
J

Joe Lovick

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,140
Latest member
SweetcalmCBDreview
Top