Precedence of operators in python/numpy: epxlicit vs. prefix notation

Viewed 18

Many Python packages allow explicit and suffix notations for functions, such as np.max(X) vs. X.max(). In what order does python carry out operations when a mixture of notations is used?

E.g., np.abs(X).min() corresponds to np.max(np.abs(X)) rather than to np.abs(np.max(X)) - does this reflects a general rule of precedence of the explicit function np.f(X) over the suffix notation X.f() or does the precedence need to be checked on a case by case basis?

1 Answers

This is always left to right, so np.abs(X).min() is equivalent to (np.abs(X)).min().

For right to left you would have needed:

np.abs(X.min())
Related