>
> Ideally, I would like in1d to always be the right answer to this problem. It
> should be easy to put in an if statement to switch to a kern_in()-type
function
> in the case of large ar1 but small ar2. I will do some timing tests and make
a
> patch.
>
I uploaded a timing test and a pa
2010/8/27 Brett Olsen :
> If there's multiple possible valid values, I've come up with a couple
> possible methods, but they all seem to be inefficient or kludges:
valid = N.array(("a", "c"))
(ar == valid[0]) | (ar == valid[1])
> array([ True, False, True, False, False, True, False, Tr
Nathaniel Smith pobox.com> writes:
> On Fri, Aug 27, 2010 at 1:35 PM, Robert Kern gmail.com>
wrote:
> > As valid gets larger, in1d() will catch up but for smallish sizes of
> > valid, which I suspect given the "non-numeric" nature of the OP's (Hi,
> > Brett!) request, kern_in() is usually bette
2010/8/27, Robert Kern :
> [~]
> |2> def kern_in(x, valid):
> ..> mask = np.zeros(x.shape, dtype=bool)
> ..> for good in valid:
> ..> mask |= (x == good)
> ..> return mask
> ..>
>
> [~]
> |6> ar = np.random.randint(100, size=100)
>
> [~]
> |7> valid = np.arange(0, 100, 5)
>
On Fri, Aug 27, 2010 at 1:35 PM, Robert Kern wrote:
> [~]
> |8> %timeit kern_in(ar, valid)
> 10 loops, best of 3: 115 ms per loop
>
> [~]
> |9> %timeit np.in1d(ar, valid)
> 1 loops, best of 3: 279 ms per loop
>
> As valid gets larger, in1d() will catch up but for smallish sizes of
> valid, which I
On Fri, Aug 27, 2010 at 15:21, Nathaniel Smith wrote:
> On Fri, Aug 27, 2010 at 1:17 PM, Robert Kern wrote:
>> But in any case, that would be very slow for large arrays since it
>> would invoke a Python function call for every value in ar. Instead,
>> iterate over the valid array, which is much s
On Fri, Aug 27, 2010 at 4:17 PM, Robert Kern wrote:
> On Fri, Aug 27, 2010 at 15:10, Ken Watford wrote:
>> On Fri, Aug 27, 2010 at 3:58 PM, Brett Olsen wrote:
>>> Hello,
>>>
>>> I have an array of non-numeric data, and I want to create a boolean
>>> array denoting whether each element in this ar
On 27 August 2010 16:17, Robert Kern wrote:
> On Fri, Aug 27, 2010 at 15:10, Ken Watford wrote:
>> On Fri, Aug 27, 2010 at 3:58 PM, Brett Olsen wrote:
>>> Hello,
>>>
>>> I have an array of non-numeric data, and I want to create a boolean
>>> array denoting whether each element in this array is a
On Fri, Aug 27, 2010 at 1:17 PM, Robert Kern wrote:
> But in any case, that would be very slow for large arrays since it
> would invoke a Python function call for every value in ar. Instead,
> iterate over the valid array, which is much shorter:
>
> mask = np.zeros(ar.shape, dtype=bool)
> for good
On Fri, Aug 27, 2010 at 15:10, Ken Watford wrote:
> On Fri, Aug 27, 2010 at 3:58 PM, Brett Olsen wrote:
>> Hello,
>>
>> I have an array of non-numeric data, and I want to create a boolean
>> array denoting whether each element in this array is a "valid" value
>> or not. This is straightforward i
On Fri, Aug 27, 2010 at 3:58 PM, Brett Olsen wrote:
> Hello,
>
> I have an array of non-numeric data, and I want to create a boolean
> array denoting whether each element in this array is a "valid" value
> or not. This is straightforward if there's only one possible valid
> value:
import num
Hello,
I have an array of non-numeric data, and I want to create a boolean
array denoting whether each element in this array is a "valid" value
or not. This is straightforward if there's only one possible valid
value:
>>> import numpy as N
>>> ar = N.array(("a", "b", "c", "b", "b", "a", "d", "c",
On Thu, Nov 26, 2009 at 7:35 PM, Nils Wagner
wrote:
>
>
> Sorry, I mixed up '+' and '&'
>
a = array(([True,True],[True,True]))
b = array(([False,False],[False,False]))
a & b
> array([[False, False],
> [False, False]], dtype=bool)
>
> Cheers,
>
> Nils
hey,
this
On Thu, 26 Nov 2009 15:14:04 +0100
Fabrice Silva wrote:
> Le jeudi 26 novembre 2009 à 14:44 +0100, Gael Varoquaux
>a écrit :
>> On Thu, Nov 26, 2009 at 02:43:14PM +0100, Fabrice Silva
>>wrote:
>> > Le jeudi 26 novembre 2009 à 18:26 +0200, Nadav Horesh
>>a écrit :
>> > > It is obvious to me th
Le jeudi 26 novembre 2009 à 14:44 +0100, Gael Varoquaux a écrit :
> On Thu, Nov 26, 2009 at 02:43:14PM +0100, Fabrice Silva wrote:
> > Le jeudi 26 novembre 2009 à 18:26 +0200, Nadav Horesh a écrit :
> > > It is obvious to me that True+False == True,. Why do you think it should
> > > be False?
>
>
On 11/26/2009 8:20 AM, Nils Wagner wrote:
> a = array(([True,True],[True,True]))
> b = array(([False,False],[False,False]))
> a+b
NumPy's boolean operations are very well behaved.
>>> a = np.array(([True,True],[True,True]))
>>> a+a
array([[ True, True],
[ True, True]], dtype=bool)
Comp
On Thu, Nov 26, 2009 at 02:43:14PM +0100, Fabrice Silva wrote:
> Le jeudi 26 novembre 2009 à 18:26 +0200, Nadav Horesh a écrit :
> > It is obvious to me that True+False == True,. Why do you think it should
> > be False?
> I would understand it is not obvious that '+' stands for logical 'or',
> and
Le jeudi 26 novembre 2009 à 18:26 +0200, Nadav Horesh a écrit :
> It is obvious to me that True+False == True,. Why do you think it should
> be False?
>
I would understand it is not obvious that '+' stands for logical 'or',
and '*' for logical 'and'...
--
Fabrice Silva
LMA UPR CNRS 7051
_
It is obvious to me that True+False == True,. Why do you think it should
be False?
Nadav
On Thu, 2009-11-26 at 14:20 +0100, Nils Wagner wrote:
> Hi all,
>
> is the following behaviour correct
>
> >>> a = array(([True,True],[True,True]))
> >>> b = array(([False,False],[False,False]))
>
> >>>
Hi all,
is the following behaviour correct
>>> a = array(([True,True],[True,True]))
>>> b = array(([False,False],[False,False]))
>>> a+b
array([[ True, True],
[ True, True]])
I have expected False.
Nils
___
NumPy-Discussion mailing list
20 matches
Mail list logo