Need efficient routine to calculate max of two arrays [message #3432] |
Tue, 24 January 1995 12:51  |
gallery
Messages: 4 Registered: August 1994
|
Junior Member |
|
|
Here is the problem:
There are two arrays: a and b of equal length, I want to calculate
an array c of the same length so that:
c(i) = min(a(i),b(i))
For efficiency, I want to use vectors and not a do loop.
Any suggestions? This would seem to be a common enough problem,
--
William O. Gallery gallery@aer.com
Atmospheric & Environmental Research Voice(617) 349-2284
840 Memorial Drive (617) 547-6207
Cambridge, Massachusetts 02139 FAX (617) 661-6479
|
|
|
Re: Need efficient routine to calculate max of two arrays [message #3530 is a reply to message #3432] |
Fri, 03 February 1995 05:51  |
sjt
Messages: 72 Registered: November 1993
|
Member |
|
|
William O. Gallery (gallery@aer.com) wrote:
: Here is the problem:
: There are two arrays: a and b of equal length, I want to calculate
: an array c of the same length so that:
: c(i) = min(a(i),b(i))
: For efficiency, I want to use vectors and not a do loop.
: Any suggestions? This would seem to be a common enough problem,
: --
: William O. Gallery gallery@aer.com
: Atmospheric & Environmental Research Voice(617) 349-2284
: 840 Memorial Drive (617) 547-6207
: Cambridge, Massachusetts 02139 FAX (617) 661-6479
I've not been following this thread so someone else may already have
given this answer which is I believe the cleanest and most efficient:
c = a < b
for the problem as stated and
c = a > b
for the problem implied in the title.
--
--
+------------------------+---------------------------------- --+---------+
| James Tappin, | School of Physics & Space Research | O__ |
| sjt@star.sr.bham.ac.uk | University of Birmingham | -- \/` |
| Ph: 021-414-6462. Fax: 021-414-3722 | |
+----------------------------------------------------------- --+---------+
|
|
|