Re: Arrays Intersection
- From: Paul van Delst <Paul.vanDelst@xxxxxxxx>
- Date: Fri, 30 May 2008 10:34:55 -0400
On 30 mei, 13:34, Infinity77 <andrea.gav...@xxxxxxxxx> wrote:Hi All,
I have received so many nice answers in this newsgroup that I
thought I could ask one more question. I am trying to find the
intersection of 2 one-dimensional integer arrays, where "intersection"
means the common elements in both arrays, i.e.:
a = [1,2,3,4,5,6]
b = [5, 6, 7]
intersection(a, b) ==> [5, 6]
On 2008-05-30 09:53:27 -0300, Arjen Markus <arjen.mar...@xxxxxxxxxx> said:You might use:
pack( array1, (/ (any(array1(i) == array2), i=1,size(array1)) /) )
On 30 mei, 16:08, Gordon Sande <g.sa...@xxxxxxxxxxxxxxxx> wrote:And allows for demonstration of arcane usage of litle used (by many)
fetures that would make an APLer proud. If the following programmers
can not follow the code it is a disservice.
If the OP had to ask it is a fair bet that arcane responses are not the
most helpful. If the OP were into serious obscure algorithms of import
to a larger code then there probably would not have been a question.
There is a well know quote on pricing of yachts that seems suited to
these situations after trivial modification.
FWIW, I don't think the code above is arcane at all. Yes, it uses two new f90/95 intrinsics, PACK and ALL, but once you know what they do, it seems quite clear.
Comparing to current scripting languages like python and ruby, the above code snippet is positively crystal like in it's clarity. I doubt coding one's own versions of PACK and ALL would be quite as readable.
We (for some suitable definition of "we") need to stop thinking that we must write code that can be understood by both our grand-children and -parents. We've got to assume the person reading the code in the future has some capability for analytical thought when they come across something they don't immediately grok.
And, besides, isn't reading other's codes and trying to understand them how we all learned Fortran? :o)
cheers,
paulv
.
- Follow-Ups:
- Re: Arrays Intersection
- From: Arjen Markus
- Re: Arrays Intersection
- References:
- Arrays Intersection
- From: Infinity77
- Re: Arrays Intersection
- From: Arjen Markus
- Re: Arrays Intersection
- From: Gordon Sande
- Re: Arrays Intersection
- From: Arjen Markus
- Re: Arrays Intersection
- From: Gordon Sande
- Re: Arrays Intersection
- From: Arjen Markus
- Arrays Intersection
- Prev by Date: Re: warning on running image !!!!!
- Next by Date: Re: Arrays Intersection
- Previous by thread: Re: Arrays Intersection
- Next by thread: Re: Arrays Intersection
- Index(es):