Thank you so much for your answer and the code.
I firstly thought of it too, and I repeated the same experiment many times and on another machine but
the error still occurs for <class ‘TwoHeads’> at the second output only.
Would it be still most likely the floating point error?