When numpy was introduced as a successor to Numeric, many things that were just functions, not methods, were added as methods of type ndarray . At this particular moment, the ability to subclass an array type was a new feature. It was believed that creating some of these common function methods would allow subclasses to do the right thing more easily. For example, using .sum() as a method is useful to allow the masked array type to ignore masked values; you can write generic code that will work for both simple ndarray and masked arrays without any branching.
Of course, you cannot get rid of functions. A good feature of functions is that they will accept any object that can be forced into ndarray , for example, a list of numbers that will not have all ndarray methods. And the specific list of functions that have been added as methods cannot be comprehensive; This is not a very good OO development. It is not necessary that all trigger functions be added, for example, as methods.
The current list of methods was mainly chosen at the beginning of numpy development for those that we thought would be useful as methods from the point of view of a subclass or nationally convenient. With a lot of experience, we came to the conclusion that we added too many methods (seriously, there is no need for .ptp() be a method), and that subclassing ndarray usually a bad idea for reasons I won't be here.
Therefore, take a list of methods, usually a subset of the list of available functions, and np.amin() and np.amax() as small renames of the .min() and .min() methods to avoid smoothing the built-in functions.
Robert Kern
source share