[Numpy-discussion] Why ufunc out arg has to be an ndarray?

2025-01-08 Thread Stefano Miccoli via NumPy-Discussion
From time to time I find myself overwriting a python buffer with the output of a ufunc, for example like this: import array import numpy as np a = array.array('f', (1,1,1)) np.exp2(a, out=np.asarray(a)) assert a.tolist() == [2, 2, 2] Here I have to wrap `out=np.asarray(a)` because the more natu

[Numpy-discussion] Re: np.ndenumerate doesn't obey mask?

2024-10-23 Thread Stefano Miccoli via NumPy-Discussion
> On 22 Oct 2024, at 18:00, numpy-discussion-requ...@python.org wrote: > > From: Neal Becker > Subject: [Numpy-discussion] np.ndenumerate doesn't obey mask? > Date: 21 October 2024 at 18:52:41 CEST > To: Discussion of Numerical Python > Reply-To: Discussion of Numerical Python > > > I was us

[Numpy-discussion] Re: Extend ldexp to handle complex inputs

2024-09-27 Thread Stefano Miccoli via NumPy-Discussion
‘np.ldexp’ exists mainly for compatibility with the C/C++ functions ldexp, ldexpf, ldexpl, which are defined for float/double/long double. Quoting the C refs: > On binary systems (where FLT_RADIX is 2), ldexp is equivalent to scalbn. > The function ldexp ("load exponent"), together with its dual,

[Numpy-discussion] Re: Comparison between numpy scalars returns numpy bool class and not native python bool class

2024-06-28 Thread Stefano Miccoli via NumPy-Discussion
> On 27 Jun 2024, at 23:48, Aaron Meurer wrote: > > Apparently the reason this happens is that True, False, and None are > compared using 'is' in structural pattern matching (see Please let me stress that the ‘match/case’ snippet was only a concrete example of a situation in which, say ‘f(a)’

[Numpy-discussion] Comparison between numpy scalars returns numpy bool class and not native python bool class

2024-06-27 Thread Stefano Miccoli via NumPy-Discussion
It is well known that ‘np.bool' is not interchangeable with python ‘bool’, and in fact 'issubclass(np.bool, bool)’ is false. On the contrary, numpy floats are subclassing python floats—'issubclass(np.float64, float) is true—so I’m wondering if the fact that scalar comparison returns a np.bool b

[Numpy-discussion] Re: Introducing quarterly date units to datetime64 and timedelta64

2024-02-24 Thread Stefano Miccoli via NumPy-Discussion
Actually quarters (3 months sub-year groupings) are already supported as ‘M8[3M]’ and ‘m8[3M]’: >>> np.datetime64('2024-05').astype('M8[3M]') - np.datetime64('2020-03').astype('M8[3M]') numpy.timedelta64(17,'3M') So explicitly introducing a ‘Q’ time unit is only to enable more int

[Numpy-discussion] Re: How is "round to N decimal places" defined for binary floating point numbers?

2023-12-29 Thread Stefano Miccoli via NumPy-Discussion
Oscar Gustafsson wrote: > I would take it that round x to N radix-R digits means > round_to_integer(x * R**N)/R**N > (ignoring floating-point issues) Yes, this is the tried-and-true way: first define the function in exact arithmetic, then ask for the floating point implementation to return an ap

[Numpy-discussion] How is "round to N decimal places" defined for binary floating point numbers?

2023-12-28 Thread Stefano Miccoli via NumPy-Discussion
I have always been puzzled about how to correctly define the python built-in `round(number, ndigits)` when `number` is a binary float and `ndigits` is greater than zero. Apparently CPython and numpy disagree: >>> round(2.765, 2) 2.77 >>> np.round(2.765, 2) 2.76 My

[Numpy-discussion] Re: Precision changes to sin/cos in the next release?

2023-05-31 Thread Stefano Miccoli via NumPy-Discussion
On 31 May 2023, at 16:32, numpy-discussion-requ...@python.org wrote: It seems fairly clear that with this recent change, the feeling is that the tradeoff is bad and that too much accuracy was lost, for not enough real-world gain. However, we now ha