Re: vector difference



Gordon Sande wrote:
On 2008-08-06 15:36:01 -0300, nospam@xxxxxxxxxxxxx (Richard Maine) said:

utab <umut.tabak@xxxxxxxxx> wrote:

real :: a(4) = (/1.,2.,3.,4./)
real :: b(1) = (/2., 3./)
(snip)
result is to be

res = (/1., 4./)

I wondered if there is a quick way to accomplish
this through intrinsic functions?

I'd say that "pack" and "any" are your friends. I'd probably do
something like
(snip of actual code using PACK and ANY)

As well as being hard to read they have the
disadvantage that the algorithms
being suggested are quadratic for a well/over researched problem that has
linear (and a bit) solutions. Perfectly acceptable for toy problems but
prone to create bottlenecks if the size grows at some later time. Having
the inputs sorted and using that fact lowers the cost markedly. Establishing
and maintaining a sorted order has it own costs.

In addition, the OP didn't specify the results in the case
that there are repeats in either list. The PACK/ANY method
will remove all copies of any matching element. That may or
may not be the desired result.

With linear traversal through two sorted lists one can
choose to remove all matching element, or only one in
list A for each match to list B.

-- glen

.



Relevant Pages

  • Re: 2 Way Linear Table regression
    ... linear least-squares fit on multiple variables. ... using lists: ... FOR k data 'cols' k GET COL- AXL NIP ...
    (comp.sys.hp48)
  • Re: Speed revisited
    ... Both essentially use a loop with ... >> snippet 2 seems after initial slowdown looks exactly linear, ... dictionaries, lists, sets, etc. ... speeds regardless of what length of tape was already read. ...
    (comp.lang.python)
  • Re: Create subspace from Basis : Maple
    ... I have the Basis vectors of a subspace. ... subspace (all possible linear combinations) from these basis vectors in ... implemented as lists or Vectors, then the span of a set of vectors V ...
    (sci.math.symbolic)
  • Re: To Those Who Trash Bubble Sort
    ... > he may have meant only to remark about Hoare's algorithm. ... let list_of_lists = partition list into lists of five elements ... Which of course comes out to be linear. ...
    (comp.programming)