I would like to find the derivative of the discrete max operator in numpy. For example, given a=np.array([1,2,3,2,1]), calling np.max(a) gives 3. Can this operation be differentiated? From thinking about what the derivative means, it seems that given a small change in a, the derivative of max(a) should be 0 unless the small change causes max(a) to change to a new value, in which case the derivative could be very large indeed. Does this line of thinking make sense at all? Many thanks!

  • $\begingroup$ $\max(x)$ is not differentiable, but if you tell us more about what you are trying to achieve, we might be able to help. $\endgroup$ Mar 18, 2020 at 5:23
  • $\begingroup$ Are you differentiating with respect to the array components? The partial derivatives exist almost everywhere, equal to $0$ or $\pm 1$. $\endgroup$
    – epimorphic
    Mar 19, 2020 at 3:37


You must log in to answer this question.

Browse other questions tagged .