> > Should `np.ndarray.bit_count()` exist? I tend against this;
Thanks for the info Sebastian, I agree with this as we can stick to what Python offers. Should `np.bit_count` exist? Having it on the int* types may be sufficient. Hey Stephan, regarding this, I felt we could support it in the same lines NumPy Mathematical Functions <https://numpy.org/doc/stable/reference/routines.math.html>, something like GCD perhaps, where we do not have `np.ndarray.gcd` but do have an `np.gcd` What is the max value of the count? 64? If so it can go in a uint8. This makes sense yeah, will make this change, thanks for the suggestion. Also, an interesting future proposal can be to club all the bitwise functions into a single "namespace" of sorts and have np.bits.*. This has already been suggested in this comment <https://github.com/numpy/numpy/issues/16325#issuecomment-869182363> and I feel this would be a clean addition and we can support other useful functions as well. Regards, Ganesh On Tue, Aug 3, 2021 at 9:18 PM Sebastian Berg <sebast...@sipsolutions.net> wrote: > 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 > > _______________________________________________ > NumPy-Discussion mailing list > NumPy-Discussion@python.org > https://mail.python.org/mailman/listinfo/numpy-discussion >
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@python.org https://mail.python.org/mailman/listinfo/numpy-discussion