Array containing maximum values for two arrays [message #86912] |
Thu, 12 December 2013 09:17  |
joellama
Messages: 8 Registered: July 2013
|
Junior Member |
|
|
Hi,
I am trying to figure out how to take two arrays and make a new array with each value is the maximum value of each of the sub elements of the two arrays, i.e.
a = [5, 6, 7]
b = [3, 8, 4]
then the resultant vector would be
c= [5, 8, 7]
Ideally I would obviously like to do this without a loop!
Any help would be really appreciated
|
|
|
Re: Array containing maximum values for two arrays [message #86913 is a reply to message #86912] |
Thu, 12 December 2013 09:21   |
joellama
Messages: 8 Registered: July 2013
|
Junior Member |
|
|
On Thursday, December 12, 2013 5:17:46 PM UTC, joel...@gmail.com wrote:
> Hi,
>
>
>
> I am trying to figure out how to take two arrays and make a new array with each value is the maximum value of each of the sub elements of the two arrays, i.e.
>
>
>
> a = [5, 6, 7]
>
> b = [3, 8, 4]
>
>
>
> then the resultant vector would be
>
> c= [5, 8, 7]
>
>
>
> Ideally I would obviously like to do this without a loop!
>
>
>
> Any help would be really appreciated
Apologies, i've just realised that max(array, dimension=2) will do what i'm after.
|
|
|
Re: Array containing maximum values for two arrays [message #86917 is a reply to message #86913] |
Thu, 12 December 2013 11:28  |
Phillip Bitzer
Messages: 223 Registered: June 2006
|
Senior Member |
|
|
On Thursday, December 12, 2013 11:21:09 AM UTC-6, joel...@gmail.com wrote:
>
> Apologies, i've just realised that max(array, dimension=2) will do what i'm after.
Well, you could do that, assuming you're concatenating your two 1D arrays in to an nx2 array. But, a more efficient way is to use the maximum operator:
c = a > b
|
|
|