Use foreach_set
to set all fcurve data from data
Similarly to this q&a can add our data directly to an fcurve.
fc.keyframe_points.foreach_set("co",
[x for co in zip(frames, samples) for x in co])
is setting the co
, the (frame, value) pair of each keyframe point
i = 0
for f, s in zip(frames, samples): # zip => (f1, s1), (f2, s2) ...
fc.keyframe_points[i].co = (f, s)
i += 1
note foreach_set
requires a "flat (or one dimensional) list" eg [f1, s1, f2, s2 ...]
flat_list = [x for co in zip(frames, samples) for x in co]
Script below creates a random noise per frame for frames 1 to 250. The action and fcurve is created for location.y
and assigned to the context object.

import bpy
from random import random
frames = range(1, 250)
samples = (random() for f in frames)
# some action
a = bpy.data.actions.new("SomeAction")
fc = a.fcurves.new("location", index=1, "LocY")
fc.keyframe_points.add(count=len(frames))
# populate points
fc.keyframe_points.foreach_set("co",
[x for co in zip(frames, samples) for x in co])
# update
fc.update()
# assign to context ob
ad = bpy.context.object.animation_data_create()
ad.action = a
To tweak it up a notch, if you are not going to edit the fcurve convert it to sampled points
fc.convert_to_samples(1, 250)
