On Feb 10, 10:45 am, John H Palmieri <[email protected]> wrote:
> On Feb 10, 10:31 am, green351 <[email protected]> wrote:
>
> > Hi.  I have the following problem: consider the following list of
> > compositions and its cartesian product with itself.
>
> > C83=Compositions(8, length=3);
> > cp=CartesianProduct(C83,C83)
>
> > I want to remove certain elements from this set/list and then to count
> > the elements left.  For example I want to remove the element [[1,1,6],
> > [1,2,5]] and in general for [[a,b,c],[d,e,f]], I want to remove it if
> > a=d=1 OR b=e=1 Or c=f=1.  There are other things I want to remove but
> > I think if I figure out the correct syntax for the above I could
> > probably figure the rest out. How would I do this?
>
> One way is to use "filter":
>
> Y = cp.filter(lambda x: x[0][0] != 1 or x[1][0] != 1)
>
> keeps pairs x=[[a,b,c], [d,e,f]] so that either a != 1 or d != 1, so
> you could do something like
>
> Y = cp.filter(lambda x: (x[0][0] != 1 or x[1][0] != 1) and (x[0][1] !=
> 1 or x[1][1] != 1) and
>                         (x[0][2] != 1 or x[1][2] != 1))

Thanks for the quick replies!
John,
So I tried the following using what you have above:

C22=Compositions(6, length=2);
cp2=CartesianProduct(C22,C22);
A= cp2.filter(lambda x: x[0][0] != 1 and x[1][1] != 1 and x[0][0] != 2
and x[1][1] != 2 and x[0][0] != 3 and x[1][1] != 3);  A.list()
[[[4, 2], [1, 5]], [[4, 2], [2, 4]], [[5, 1], [1, 5]], [[5, 1], [2,
4]]]

My goal here is to get rid of ALL [[a,b],[c,d]] with a=c or b=d.  But
why does it also get rid of [[3,3],[2,4]]?  Maybe I don't understand
the syntax.  I'm guessing x[0][0] ! =1 refers to the element x= [[a,b],
[c,d]] with a=c=1.  Is this correct?

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to