Log in

View Full Version : Problem with Merge


hello_hello
2nd December 2025, 10:30
I'm using VapourSynth r72 on Linux and I can't upgrade to r73 or test this on Windows at the moment, however.......

I've been trying to add ringing repair to a resizing function but I kept bumping into errors pointing to the VapourSynth Merge function. Even so, I spent an hour or three trying to find an error in my function that was supplying Merge with silly variables before I released that wasn't the problem. Or maybe I'm losing my mind.....

from scipy.interpolate import CubicSpline

CSpline = CubicSpline([1, 2.25, 3.5], [0, 1, 0], bc_type='natural')

Z = 960*540/704/396

Weight = CSpline(min(max(Z, 1), 2.25))

clip = core.sub.Subtitle(clip, str(Weight)).set_output()

Screenshot.

https://i.imgur.com/sOC7nzF.png

Same again, but with this replacing the final line above:

clip = core.std.Merge(clip, clip, Weight).set_output()

Failed to evaluate the script:
Python exception: iteration over a 0-d array

Traceback (most recent call last):
File "src/cython/vapoursynth.pyx", line 3378, in vapoursynth._vpy_evaluate
File "src/cython/vapoursynth.pyx", line 3379, in vapoursynth._vpy_evaluate
File "/media/NVME2/New Folder 2/Test.vpy", line 44, in
File "src/cython/vapoursynth.pyx", line 3098, in vapoursynth.Function.__call__
File "src/cython/vapoursynth.pyx", line 3089, in vapoursynth.Function.__call__
File "src/cython/vapoursynth.pyx", line 1054, in vapoursynth.typedDictToMap
TypeError: iteration over a 0-d array

The resolution of the videos being merged doesn't seem to change anything (only tested YV12). For the record, this works without any error.

clip = core.std.Merge(clip, clip, 0.868856119546547).set_output()

Myrsloik
2nd December 2025, 13:27
I bet print(Weight) returns some kind of object and not a float

hello_hello
2nd December 2025, 14:08
It's beyond my limited understanding at the moment, but for some reason I'm sure I can use lots of equations to define "Z", and some work while some don't. For the example I posted above though, I checked here: https://www.w3schools.com/python/trypython.asp?filename=demo_ref_isinstance

print(Weight) 0.868856119546547
print(isinstance(Weight, float)) False
print(type(Weight)) <class 'numpy.ndarray'>

Z = 960*540/704/396
Weight = CSpline(min(max(Z, 1), 2.25))
Weight = round(Weight * 1000000) / 1000000

print(type(Weight)) <class 'float'>

I'd already added
round(Weight * 1000000) / 1000000
as so far it's solved the problem, even if I don't fully understand why, as the value only needs to be accurate to a few decimal places.

Is there a "more correct" solution though?

Cheers.

Edit: I guess the other thing that may have led me down the rabbit hole, is there's a final line in the calculation that wasn't producing an error, so because of that I assumed Weight must be float. Yet.....

Z = 960*540/704/396
Weight = CSpline(min(max(Z, 1), 2.25))
Weight = min(max(Weight, 0), 1)

print(isinstance(Weight, float)) False

This probably also contributed to my confusion.

Z = 960*540/704/396
Weight = CSpline(min(max(Z, 1), 2.25))
Weight = min(max(Weight, 0), 1)

print(Weight > 0) True

_Al_
2nd December 2025, 20:08
Weight and CSpline are the same type of objects: numpy.ndarray
Weight is corresponding array to CSpline array on the curve. In your case CSpline is one item nd.array so one item is returned in Weight object.

And while using:
Weight = min(max(Weight, 0), 1)
it does not change Weight into another value or type, it is still np.ndarray ,
but if you use math, then math is involved, and result is float

for one dimensional array, you can get that item out like:
float_weight = Weight.item((0))

sorry, it looks CSpline is not the same object as Weight, but anyway, that item from Weight could be fished out as above.
You put one argument into CSpline function (could be array), so you got one item np.array as Weight.

hello_hello
2nd December 2025, 20:46
And while using:
Weight = min(max(Weight, 0), 1)
it does not change Weight into another value or type, it is still np.ndarray ,
but if you use math, then math is involved, and result is float

For a one dimensional array, I think if the single array item (Weight) was less than or equal to zero, or greater than or equal to one,
min(max(Weight, 0), 1) was outputting zero and one, which is why some resizing amounts (or values) for CSpline weren't producing an error while some were, and I was to silly to work out that was the reason.

for one dimensional array, you can get that item out like:
float_weight = Weight.item((0))

Yep, that does the trick.

Thanks.