[Tutor] array
Danny Yoo
dyoo@decrem.com
Sun, 17 Mar 2002 21:33:34 -0800 (PST)
On Sun, 17 Mar 2002, Paul Sidorsky wrote:
> Karshi wrote:
>
> > How do find the maximum number in an array: say A[i,j] ?
> > I've got the following error when I tried to use "max":
> > --------------------------------------------------------------------
> > >>> M=array([[1,2,3,],[3,4,56],[4,6,8]], Float32)
> > >>> M
> > array([[ 1., 2., 3.],
> > [ 3., 4., 56.],
> > [ 4., 6., 8.]],'f')
> > >>> max(M)
> > array([ 4., 6., 8.],'f')
> > ---------------------------------------------------------------------
> > which is not true.
Numeric's 'Ufuncs' work on entire columns at a time, so you may need to
apply the max() Ufunc twice to get the effect you want:
###
>>> from Numeric import *
>>> M = array([[1, 2, 3],
... [4, 5, 6],
... [7, 8, 9]])
>>>
>>> M
array([[1, 2, 3],
[4, 5, 6],
[7, 8, 9]])
>>> max(M)
array([7, 8, 9])
>>> max(max(M))
9
###
You can read more details about Ufuncs here:
http://www.pfdubois.com/numpy/html2/numpy-7.html#pgfId-36126
Good luck!