How to obtain max and min of f-curve in python I am making an add-on for Blender. You can find it here: https://github.com/rubeste/Blender_f-curve_select
I need to support the normalization of the curve as well. So, I need to calculate the f-curves position.
I currently do this by getting the minimum and maximum value of the curve and creating a range between 1 and -1.
My problem is that I do this calculation by looking through the whole animation. This takes time, and I only tested it with 3 curves.
I was wondering if there is a better way to obtain the minimum and maximum. Or if I can get the value I want via a different method.
def calculateValeOfNormalizedCurve(self, context, fCurve, frame):
        start = context.scene.frame_start
        end = context.scene.frame_end
        values = []
        value = fCurve.evaluate(frame)
        i = start
        while i &lt;= end:
            values.append(fCurve.evaluate(i))
            i += 0.1
        max = np.max(values)
        min = np.min(values)
        return ((value-min)/(max-min)*2)-1
Vectorize evaluate with numpy
Having done similar via What&#39;s the range of values on a sound-baked f-curve?
Can vectorize the fcurve evaluate method and pass in an numpy array of frames, then  using methods available  get the minimum maximum etc.
Will find this much quicker than looping as in question code above.
Test script finds the minimum of each fcurve of each action from frames 1 to 250 using 0.01 subframe increments.
import bpy
import numpy as np

frames = np.arange(1, 250, 0.01)

for action in bpy.data.actions:
    print(f&quot;{action.name}&quot;)
    
    for fc in action.fcurves:
        print(f&quot;{fc.data_path}[{fc.array_index}]&quot;)
        points = np.vectorize(fc.evaluate)(frames)


        print(f&quot;min {points.min()} at {frames[np.argmin(points)]}&quot;)