Hi Carlos, On Thu, Mar 6, 2025, at 10:08, Carlos Martin wrote: > 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.
I'm curious, would this be roughly: def bit_width(x): y = np.zeros(len(x), dtype=float) mask = (x != 0) y[mask] = 1 + np.floor(np.log2(x[mask])) return y plus some error checking to ensure you don't run it on unsigned or floating point types? Stéfan _______________________________________________ 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/numpy-discussion.python.org/ Member address: arch...@mail-archive.com