Re: difference between 2 arrays
En Thu, 20 Aug 2009 06:54:05 -0300, <""Michel Claveau - MVP"> escribió: Yes, the module sets is written, in doc, like "deprecated". But: - sets exist in Python 2.6 (& 2.5 or 2.4) - documentation of sets (module) is better tha, documentation of set (builtin) The best: read the documentaion of the module, and use the builtin... Any suggestion to improve the builtin set documentation? In what ways do you see one is better than the other? -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: difference between 2 arrays
(envoyé via news:\\news.wanadoo.fr\comp.lang.python) Hi! Yes, the module sets is written, in doc, like "deprecated". But: - sets exist in Python 2.6 (& 2.5 or 2.4) - documentation of sets (module) is better tha, documentation of set (builtin) The best: read the documentaion of the module, and use the builtin... @-salutations -- MCI -- http://mail.python.org/mailman/listinfo/python-list
Re: difference between 2 arrays
19-08-2009 o 10:56:20 <""Michel Claveau - MVP"> wrote: (envoyé via news:\\news.wanadoo.fr\comp.lang.python) Hi! See the module "sets" No, see the builtin set type. Module sets is deprecated (removed in Py 3.x) -- Jan Kaliszewski (zuo) -- http://mail.python.org/mailman/listinfo/python-list
Re: difference between 2 arrays
On 19 Aug, 01:48, Pierre wrote: > Well, the equivalence of setdiff in matlab... That would be numpy.setdiff1d. -- http://mail.python.org/mailman/listinfo/python-list
Re: difference between 2 arrays
On 2009-08-19 01:48 AM, Pierre wrote: Hello, I would like to know how to find the difference (set operation) between 2 arrays : a = array([1,2, 3,2,5,2]) b = array([1,2]) I want a - b = [3,5] Well, the equivalence of setdiff in matlab... You will want to ask numpy questions on the numpy mailing list. http://www.scipy.org/Mailing_Lists Using set() is frequently a good option, but for large arrays, you will want to avoid the overhead of converting to and from sets and use numpy.setdiff1d(a, b): In [2]: a = array([1,2, 3,2,5,2]) In [3]: b = array([1,2]) In [4]: numpy.setdiff1d(a, b) Out[4]: array([3, 5]) -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list
Re: difference between 2 arrays
baalu aanand wrote: > On Aug 19, 1:48 pm, Pierre wrote: >> Hello, >> >> I would like to know how to find the difference (set operation) >> between 2 arrays : >> >> a = array([1,2, 3,2,5,2]) >> b = array([1,2]) >> I want a - b = [3,5] >> >> Well, the equivalence of setdiff in matlab... >> >> I thought a.difference(b) could work, but no : AttributeError: >> 'numpy.ndarray' object has no attribute 'difference' >> >> Thanks ! > > > > Hi, > > Here I have given my logic, check whether it helps for you > > a = [1,2, 3,2,5,2] > b = [1,2] > j = 0 > dif = [] > for i in range(len(a)) : >if a[i] not in b: > dif.append(a[i]) > j += 1 > > print dif[k] EEEK, quadratic behavior!! Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: difference between 2 arrays
On Wed, Aug 19, 2009 at 4:48 AM, Pierre wrote: > Hello, > > I would like to know how to find the difference (set operation) > between 2 arrays : > > a = array([1,2, 3,2,5,2]) > b = array([1,2]) > I want a - b = [3,5] > > Well, the equivalence of setdiff in matlab... > > I thought a.difference(b) could work, but no : AttributeError: > 'numpy.ndarray' object has no attribute 'difference' > > Thanks ! > -- > http://mail.python.org/mailman/listinfo/python-list > import numpy a = numpy.array([1,2,3,2,5,2]) b = numpy.array([1,2]) c = list(set(a)-set(b)) # or c = numpy.array(list(set(a)-set(b))) if you want to continue w/ arrays print c -- http://mail.python.org/mailman/listinfo/python-list
Re: difference between 2 arrays
Pierre (19.08.2009 10:48): Hello, I would like to know how to find the difference (set operation) between 2 arrays : a = array([1,2, 3,2,5,2]) b = array([1,2]) I want a - b = [3,5] What about set()? >>> a = set([1,2, 3,2,5,2]) >>> b = set([1,2]) >>> a.difference(b) set([3, 5]) Matthias -- http://mail.python.org/mailman/listinfo/python-list
Re: difference between 2 arrays
On Aug 19, 1:48 pm, Pierre wrote: > Hello, > > I would like to know how to find the difference (set operation) > between 2 arrays : > > a = array([1,2, 3,2,5,2]) > b = array([1,2]) > I want a - b = [3,5] > > Well, the equivalence of setdiff in matlab... > > I thought a.difference(b) could work, but no : AttributeError: > 'numpy.ndarray' object has no attribute 'difference' > > Thanks ! Hi, Here I have given my logic, check whether it helps for you a = [1,2, 3,2,5,2] b = [1,2] j = 0 dif = [] for i in range(len(a)) : if a[i] not in b: dif.append(a[i]) j += 1 print dif Thanks Baalu -- http://mail.python.org/mailman/listinfo/python-list
Re: difference between 2 arrays
On Aug 19, 1:48 pm, Pierre wrote: > Hello, > > I would like to know how to find the difference (set operation) > between 2 arrays : > > a = array([1,2, 3,2,5,2]) > b = array([1,2]) > I want a - b = [3,5] > > Well, the equivalence of setdiff in matlab... > > I thought a.difference(b) could work, but no : AttributeError: > 'numpy.ndarray' object has no attribute 'difference' > > Thanks ! Hi, Here I have given my logic, check whether it helps for you a = [1,2, 3,2,5,2] b = [1,2] j = 0 dif = [] for i in range(len(a)) : if a[i] not in b: dif.append(a[i]) j += 1 print dif[k] Thanks Baalu -- http://mail.python.org/mailman/listinfo/python-list
Re: difference between 2 arrays
On Aug 19, 6:56 pm, "Michel Claveau - MVP" wrote: > See the module "sets" See especially the notice at the front of the current sets doc which says "deprecated since 2.6" and the comparison down the end which explains why the built-in set() and frozenset() are better than the sets module. Starting now to use the sets module is not a good idea unless the OP is stuck on using Python 2.3 . -- http://mail.python.org/mailman/listinfo/python-list
Re: difference between 2 arrays
Re ! Juste pour signaler qu'il existe un newsgroup en français sur Python, qui permet de recevoir des réponses en français (donc plus complètes/détaillées). @-salutations -- Michel Claveau -- http://mail.python.org/mailman/listinfo/python-list
Re: difference between 2 arrays
(envoyé via news:\\news.wanadoo.fr\comp.lang.python) Hi! See the module "sets" @-salutations -- Michel Claveau -- http://mail.python.org/mailman/listinfo/python-list
Re: difference between 2 arrays
Pierre wrote: > Hello, > > I would like to know how to find the difference (set operation) > between 2 arrays : > > a = array([1,2, 3,2,5,2]) > b = array([1,2]) > I want a - b = [3,5] > > Well, the equivalence of setdiff in matlab... > > I thought a.difference(b) could work, but no : AttributeError: > 'numpy.ndarray' object has no attribute 'difference' Not sure if this works with numpy-arrays, but set(a) - set(b) might just work if the arrays are iterable. Diez -- http://mail.python.org/mailman/listinfo/python-list
difference between 2 arrays
Hello, I would like to know how to find the difference (set operation) between 2 arrays : a = array([1,2, 3,2,5,2]) b = array([1,2]) I want a - b = [3,5] Well, the equivalence of setdiff in matlab... I thought a.difference(b) could work, but no : AttributeError: 'numpy.ndarray' object has no attribute 'difference' Thanks ! -- http://mail.python.org/mailman/listinfo/python-list