[Numpy-discussion] extract elements of an array that are contained in another array?

josef.pktd@gmai... josef.pktd@gmai...
Thu Jun 4 19:49:13 CDT 2009


On Thu, Jun 4, 2009 at 4:52 PM, Gael Varoquaux
<gael.varoquaux@normalesup.org> wrote:
> On Thu, Jun 04, 2009 at 04:43:39PM -0400, josef.pktd@gmail.com wrote:
>> Just using "in" might promise more than it does, eg. it works only for
>> one dimensional arrays, maybe "in1d". With "in",
>
> Then 'in_1d'

No, if the breaks in a name are obvious, I still prefer names without
underscores. I don't think `1d` or `2d` needs to be separated from the
word, "in1d"
I always remember how to spell unique1d, but I usually have to check
how to spell at_least_2d, or maybe atleast_2d or even atleast2d.

how about

def setmember1d_nu(a, b):
    ...

#aliases
set_member_1d_but_it_does_not_really_have_to_be_a_set = setmember1d_nu
in1d = setmember1d_nu

Josef

>>> [f for f in dir(np) if f[-2:]=='1d' or f[-2:]=='2d']
['atleast_1d', 'atleast_2d', 'ediff1d', 'histogram2d', 'intersect1d',
'poly1d', 'setdiff1d', 'setmember1d', 'setxor1d', 'union1d',
'unique1d']

>>> [f for f in dir(scipy.signal) if f[-2:]=='1d' or f[-2:]=='2d']
['atleast_1d', 'atleast_2d', 'convolve2d', 'correlate2d', 'cspline1d',
'cspline2d', 'medfilt2d', 'qspline1d', 'qspline2d', 'sepfir2d']
>>>
>>> [f for f in dir(scipy.stats) if f[-2:]=='1d' or f[-2:]=='2d']
[]
>>>
>>> [f for f in dir(scipy.ndimage) if f[-2:]=='1d' or f[-2:]=='2d']
['convolve1d', 'correlate1d', 'gaussian_filter1d', 'generic_filter1d',
'maximum_filter1d', 'minimum_filter1d', 'spline_filter1d',
'uniform_filter1d']


>
>> I found arraysetops because of unique1d, but I didn't figure out what
>> the subpackage really does, because I was reading "arrayse-tops"
>> instead of array-set-ops"
>
> That's why I push people to use more underscores. IMHO PEP8 lacks a push
> for underscores.
>
> Gaël
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>


More information about the Numpy-discussion mailing list