[Numpy-discussion] ENH: Add a non-circular shift function

2025-07-16 Thread Carlos Martin
Feature request: Add a non-circular shift function that is similar to [`numpy.roll`](https://numpy.org/doc/stable/reference/generated/numpy.roll.html) but, instead of wrapping elements around, replaces unoccupied entries with a specified fill value. Examples: ``` >>> import numpy as np >>> a =

[Numpy-discussion] ENH: More user-friendly way to pad a specific axis

2025-06-24 Thread Carlos Martin
It is common to want to pad an array along a *specific* axis. Examples: - https://stackoverflow.com/questions/72106542/how-to-pad-the-i-j-axes-of-a-3d-np-array-without-padding-its-k-axis - https://stackoverflow.com/questions/56076094/zero-pad-ndarray-along-axis - https://stackoverflow.com/questi

[Numpy-discussion] Re: ENH: Let numpy.size accept multiple axes

2025-06-19 Thread Carlos Martin
Correction: [`math.prod`](https://docs.python.org/3/library/math.html#math.prod). ___ NumPy-Discussion mailing list -- numpy-discussion@python.org To unsubscribe send an email to numpy-discussion-le...@python.org https://mail.python.org/mailman3//lists/n

[Numpy-discussion] ENH: Let numpy.size accept multiple axes

2025-06-19 Thread Carlos Martin
Let the `axis` argument of [`numpy.size`](https://numpy.org/doc/stable/reference/generated/numpy.size.html) accept a tuple of ints (like other functions that take an `axis` argument) to measure the size for multiple axes. This should be straightforward to implement with [`itertools.product`](h

[Numpy-discussion] Re: ENH: Add reverse argument to ufunc.accumulate, cumsum, nancumsum, cumprod, nancumprod

2025-06-09 Thread Carlos Martin
My particular use case was computing cumulative returns in the context of reinforcement learning. A GitHub code search suggests that reverse cumsum is a fairly common operation, with 3.8k hits: https://github.com/search?q=%2Fcumsum%5C%28.*%5C%5B%3A%3A-1%5C%5D%5C%29%5C%5B%3A%3A-1%5C%5D%2F&type=c

[Numpy-discussion] ENH: Add reverse argument to ufunc.accumulate, cumsum, nancumsum, cumprod, nancumprod

2025-06-07 Thread Carlos Martin
Add a reverse argument to accumulating functions that, when true, causes the accumulation to be performed in reverse. Examples: - ufunc.accumulate: https://numpy.org/doc/stable/reference/generated/numpy.ufunc.accumulate.html - cumsum: https://numpy.org/doc/stable/reference/generated/numpy.cumsum

[Numpy-discussion] ENH: Add saturating arithmetic functions

2025-04-26 Thread Carlos Martin
Saturating arithmetic (https://en.wikipedia.org/wiki/Saturation_arithmetic) is important in digital signal processing and other areas. Feature request: Add saturating arithmetic functions for the following basic operations: - addition (C++ counterpart: https://en.cppreference.com/w/cpp/numeric/

[Numpy-discussion] Add a "broadcast" option to numpy.concatenate

2025-03-18 Thread Carlos Martin
Often, I've wanted to concatenate arrays with different ndims along a particular axis, broadcasting the other axes as needed. Others have sought this functionality as well: - https://stackoverflow.com/questions/56357047 - https://github.com/numpy/numpy/issues/2115 - https://stackoverflow.com/qu

[Numpy-discussion] Re: Add a bit_width function

2025-03-06 Thread Carlos Martin
Hi Stefan, It should work on unsigned integer types and use exact computation (not floating-point computations like np.log2). For an example, see https://graphics.stanford.edu/~seander/bithacks.html#IntegerLogDeBruijn. ___ NumPy-Discussion mailing lis

[Numpy-discussion] Add a bit_width function

2025-03-06 Thread Carlos Martin
Feature request: Add a `bit_width` function to NumPy's [bit-wise operations](https://numpy.org/doc/stable/reference/routines.bitwise.html) that computes the [bit-width](https://en.wikipedia.org/wiki/Bit-width) (also called bit-length) of an input. For an example, see C++'s [`bit_width`](https:

[Numpy-discussion] Add a spectral_radius function

2025-03-01 Thread Carlos Martin
Add a function called `spectral_radius` that computes the [spectral_radius](https://en.wikipedia.org/wiki/Spectral_radius) of a given matrix. A naive way to do this is `np.max(np.abs(np.linalg.eigvals(a)))`, but there are more efficient methods. ___ N

[Numpy-discussion] Add diagonal offset argument to all functions that are missing it

2025-02-09 Thread Carlos Martin
The following functions accept a diagonal offset argument: - https://numpy.org/doc/stable/reference/generated/numpy.diag.html - https://numpy.org/doc/stable/reference/generated/numpy.diagflat.html - https://numpy.org/doc/stable/reference/generated/numpy.diagonal.html - https://numpy.org/doc/stable/

[Numpy-discussion] Feature request: Add out-of-place (i.e. pure) versions of all existing in-place operations

2024-11-14 Thread Carlos Martin
Feature request: Add out-of-place (i.e. pure) versions of all existing in-place operations, such as the following: - https://numpy.org/doc/stable/reference/generated/numpy.fill_diagonal.html - https://numpy.org/doc/stable/reference/generated/numpy.put.html - https://numpy.org/doc/stable/reference/

[Numpy-discussion] Extend ldexp to handle complex inputs

2024-09-25 Thread Carlos Martin
Currently, [ldexp](https://numpy.org/doc/stable/reference/generated/numpy.ldexp.html) throws a TypeError on a complex input: ```python3 import numpy as np def naive_ldexp(x, n): return x * 2**n def new_ldexp(x, n): if np.iscomplex(x): y = np.empty_like(x) y.real = np.ld

[Numpy-discussion] ENH: Uniform interface for accessing minimum or maximum value of a dtype

2024-08-25 Thread Carlos Martin
As discussed [here](https://github.com/numpy/numpy/issues/5032#issuecomment-1830838701), [here](https://github.com/numpy/numpy/issues/5032#issuecomment-2307927804), and [here](https://github.com/google/jax/issues/18661#issuecomment-1829031914), I'm interested in a uniform interface for accessin

[Numpy-discussion] ENH: Add more default arguments to various functions

2024-06-04 Thread Carlos Martin
Suggestion: Add the following default arguments to the following functions: - https://numpy.org/doc/stable/reference/generated/numpy.zeros.html: shape=() - https://numpy.org/doc/stable/reference/generated/numpy.ones.html: shape=() - https://numpy.org/doc/stable/reference/generated/numpy.empty.html

[Numpy-discussion] Re: ENH: Add "where" argument to reduction functions that are missing it

2024-04-08 Thread Carlos Martin
This also applies to - https://numpy.org/doc/stable/reference/generated/numpy.argmax.html - https://numpy.org/doc/stable/reference/generated/numpy.argmin.html and their nan* counterparts. An `initial` argument could be added to handle the empty case, as with np.max and np.min. ___

[Numpy-discussion] ENH: Add "where" argument to reduction functions that are missing it

2024-03-14 Thread Carlos Martin
The following reduction functions receive a "where" argument: - https://numpy.org/doc/stable/reference/generated/numpy.max.html - https://numpy.org/doc/stable/reference/generated/numpy.min.html - https://numpy.org/doc/stable/reference/generated/numpy.sum.html - https://numpy.org/doc/stable/referenc