# NArray help

**URL:** <https://www.ruby-forum.com/t/narray-help/151106>\
**Category:** Ruby\
**Created:** [October 16, 2008, 9:32pm UTC](https://www.ruby-forum.com/t/narray-help/151106 "2008-10-16T21:32:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ldt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/c0e974/32.png) [@ldt](https://www.ruby-forum.com/u/ldt)\
**Post date:** [October 16, 2008, 9:32pm UTC](https://www.ruby-forum.com/t/narray-help/151106/1 "2008-10-16T21:32:18Z")

</div>

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](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

---

<div class="post-metadata">

**Author:** ![ldt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/c0e974/32.png) [@ldt](https://www.ruby-forum.com/u/ldt)\
**Post date:** [October 16, 2008, 9:40pm UTC](https://www.ruby-forum.com/t/narray-help/151106/2 "2008-10-16T21:40:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ldt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/c0e974/32.png) [@ldt](https://www.ruby-forum.com/u/ldt)\
**Post date:** [October 16, 2008, 9:55pm UTC](https://www.ruby-forum.com/t/narray-help/151106/3 "2008-10-16T21:55:13Z")

</div>

> 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
