Re: [Numpy-discussion] Revert the return of a single NaN for `np.unique` with floating point numbers?

2021-08-03 Thread Matti Picus


On 2/8/21 8:49 pm, Ralf Gommers wrote:



On Mon, Aug 2, 2021 at 7:04 PM Sebastian Berg 
mailto:sebast...@sipsolutions.net>> wrote:


Hi all,

In NumPy 1.21, the output of `np.unique` changed in the presence of
multiple NaNs.  Previously, all NaNs were returned when we now only
return one (all NaNs were considered unique):

    a = np.array([1, 1, np.nan, np.nan, np.nan])

Before 1.21:

    >>> np.unique(a)
    array([ 1., nan, nan, nan])

After 1.21:

    array([ 1., nan])


This change was requested in an old issue:

https://github.com/numpy/numpy/issues/2111


And happened here:

https://github.com/numpy/numpy/pull/18070


While, it has a release note.  I am not sure the change got the
attention it deserved.  This would be especially worrying if it is a
regression for anyone?


I think it's now the expected answer, not a regression. `unique` is 
not an elementwise function that needs to adhere to IEEE-754 where nan 
!= nan. I can't remember reviewing this change, but it makes perfect 
sense to me.


Cheers,
Ralf



We were discussing this today (me and Matthew) and came up with an edge 
case when using set(a), it will return the old value. We should add this 
as a documented "feature"


Matti

___
NumPy-Discussion mailing list
NumPy-Discussion@python.org
https://mail.python.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Proposal for adding bit_count

2021-08-03 Thread Sebastian Berg
On Mon, 2021-08-02 at 13:10 -0700, Stefan van der Walt wrote:
> On Mon, Aug 2, 2021, at 10:50, Sebastian Berg wrote:
> > * Should `np.ndarray.bit_count()` exist?  I tend against this;
> >   but we should have it on (integer) scalars to mirror the
> >   Python `int`.
> 
> Should `np.bit_count` exist?  Having it on the int* types may be
> sufficient.

Right, we could add it only to the integer scalars mostly for Python
compatibility.  The PR suggests to create a ufunc to make the feature
available to typical NumPy code (allow using it with arrays).

> 
> > * The return value is currently the same type as the input.  That
> >   means that: `np.bit_count(uint8)` returns the count as `uint8`
> >   while `np.bit_count(int32)` returns it as `int32`, etc.
> 
> What is the max value of the count?  64?  If so it can go in a uint8.

Yes, uint8 would even work for 128 bit integers.  I was a bit unsure
about this, since we rarely create non-default integer arrays unless
prompted, but it is a good option as well.

Cheers,

Sebastian


> 
> Stéfan
> ___
> NumPy-Discussion mailing list
> NumPy-Discussion@python.org
> https://mail.python.org/mailman/listinfo/numpy-discussion



signature.asc
Description: This is a digitally signed message part
___
NumPy-Discussion mailing list
NumPy-Discussion@python.org
https://mail.python.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] NumPy Community Meeting Wednesday

2021-08-03 Thread Sebastian Berg
Hi all,

There will be a NumPy Community meeting Wednesday August 4th at
20:00 UTC. Everyone is invited and encouraged to
join in and edit the work-in-progress meeting topics and notes at:

https://hackmd.io/76o-IxCjQX2mOXO_wwkcpg?both

Best wishes

Sebastian


signature.asc
Description: This is a digitally signed message part
___
NumPy-Discussion mailing list
NumPy-Discussion@python.org
https://mail.python.org/mailman/listinfo/numpy-discussion