[Numpy-discussion] largest matrix element
Tim Hochberg
tim.hochberg at ieee.org
Tue Jul 24 14:50:34 CDT 2001
Hi Scott, et al.
First off I goofed -- that last reply should have gone to the list as a
whole.
Second, mere seconds after I pushed send I realized one problem with it:
'flat' only works for contiguous arrays. Its probably safer to use ravel
after all, unless it's known that the array is contiguous.
On the other hand, it would be slightly more efficient to ravel the matrix
after taking its absolute value since ravel potentially allocates a new
array and an array of Floats is going to be half the size of an array of
Complexes. But then we know the resulting array is going to be contiguous.
So after rewriting and erasing the thing a few times I end up with:
max(abs(a).flat)
Which is almost the same as my first one, except that the flat has been
moved and now it should work when the array starts out noncontiguous.
-tim
> Hi Tim,
>
> Looks good to me! ;)
>
> Scott
>
> Tim Hochberg wrote:
> >
> > ----- Original Message -----
> > From: "Scott Ransom" <ransom at cfa.harvard.edu>
> > Cc: <nils.wagner at freenet.de>; <numpy-discussion at lists.sourceforge.net>
> > Sent: Tuesday, July 24, 2001 12:24 PM
> > Subject: Re: [Numpy-discussion] largest matrix element
> >
> > > Charles G Waldman wrote:
> > > >
> > > > nils.wagner at freenet.de writes:
> > > > > Given a complex Matrix A(m,n)
> > > > > How can I get the absolute value of the largest matrix element
> > > > > very efficiently ?
> > > >
> > > > How about
> > > >
> > > > sqrt(max((asarray(A)*conjugate(asarray(A))).real))
> > >
> > > I if you want the global maximum you need a ravel in there:
> > >
> > > sqrt(max(ravel((asarray(a)*conjugate(asarray(a))).real)))
> >
> > I must be missing something. What's wrong with:
> >
> > max(abs(a.flat)) ?
> >
> > -tim
>
> --
> Scott M. Ransom Address: Harvard-Smithsonian CfA
> Phone: (617) 496-7908 60 Garden St. MS 10
> email: ransom at cfa.harvard.edu Cambridge, MA 02138
> GPG Fingerprint: 06A9 9553 78BE 16DB 407B FFCA 9BFA B6FF FFD3 2989
More information about the Numpy-discussion
mailing list