[Numpy-discussion] method to calculate the magnitude squared

Nathaniel Smith njs at pobox.com
Thu Oct 8 18:05:09 EDT 2015

Hi Phillip,

My advice would be to stick with the function call. It's consistent with
most other array operations (esp. when you consider that the vast majority
of operations on arrays are functions defined in third party libraries like
yours), and the more things we add to the core array object, the more work
it is for people implementing new array-style containers. I definitely
would not recommend subclassing ndarray for this purpose -- there are all
kinds of subtle problems that you'll run into that mean it's extremely
difficult to do well, and may well be impossible to do perfectly.

Good luck,
On Oct 5, 2015 21:08, "Phillip Feldman" <phillip.m.feldman at gmail.com> wrote:

> My apologies for the slow response; I was experiencing some technical
> problems with e-mail.
> In answer to Antoine's question, my main desire is for a numpy ndarray
> method, for the convenience, with a secondary goal being improved
> performance.
> I have added the function `magsq` to my library, but would like to access
> it as a method rather than as a function. I understand that I could create
> a class that inherits from NumPy and add a `magsq` method to that class,
> but this has a number of disadvantages.
> Phillip
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> https://mail.scipy.org/mailman/listinfo/numpy-discussion
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20151008/737c9285/attachment.html>

More information about the NumPy-Discussion mailing list