'ValueError: The array returned by a function changed size between calls when using scipy.fsolve()

I am trying to use scipy.optimize.fsolve() to check if some lines intersect some planes but keep getting the error above. My code is:

def colision_detection(self, moving_mic, final_position):
    other_mics = [mic for mic in self.mics if mic != moving_mic]

    segments = [(motor.position, mic.position - motor.position) for mic in other_mics for motor in mic.motors]
    planes = [(motor.position, np.cross(moving_mic.position - motor.position, final_position - motor.position)) for motor in moving_mic.motors]

    def intersection(t, plane, segment):
        # n*(r-b)=0

        r = t * segment[1] + segment[0]
        n = plane[1]
        b = plane[0]

        return n*(r-b)

    for plane in planes:
        for segment in segments:
            try:
                ans = fsolve(intersection, x0=0, args=(plane, segment))
                self.logger.info(ans)

                if  0<= ans <=1:
                    return False

            except Exception as error:
                self.logger.exception(error)
    
    return True

I keep getting the error:

ValueError: The array returned by a function changed size between calls

The position of the mics and the motors are three dimensional numpy arrays.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source