Apply relative rotation from one armature to another

I have an armature in pose mode on which I am able to rotate the bones around and I want to replicate the relative rotation of each bone on another armature. So if I rotate the arm by 90 degree on the first armature, the same should happen on the other one.

Here is the code I use for every bone in the target armature:

# Calculate rotation on the reference armature to get from the its tpose to its new pose
offset_to_new_pose = reference_tpose.inverted() @ reference_new_pose

# Add this rotation to the target tpose
bone.rotation_quaternion = target_tpose @ offset_to_new_pose

Here is the reference armature in tpose and in new pose:
reference armature: tpose and target pose

And here is the target armature in tpose and in the calculated new pose:
enter image description here

As you can see the bones are rotated in a different direction compared to the reference armature. But I want to replicate the rotation in the same direction.

Here is the exact calculation results for the selected bone in the images:

# Calculation of the offset from the reference armature
reference_tpose = Quaternion (w=0.7071, x=-0.0000, y=0.7071, z=-0.0000)
reference_new_pose = Quaternion (w=-0.4945, x=-0.4722, y=-0.5239, z=0.5080)
offset_to_new_pose = Quaternion (w=-0.7201, x=-0.6931, y=-0.0208, z=0.0253)

# Bone rotation of target armature before adding offset
bone.rotation_quaternion = Quaternion (w=1.0000, x=0.0000, y=0.0000, z=0.0000)

# Bone rotation after adding offset
bone.rotation_quaternion = Quaternion (w=-0.7201, x=-0.6931, y=-0.0208, z=0.0253)

What am I missing here? Is my calculation incorrect? Do I have to account for something that I’m currently missing? Are the axes incorrect?

Thanks in advance!

If you want relative rotation, you can’t assign absolute values to the target bone. It needs to be culmulative.

Try something like this

offset_to_new_pose = reference_new_pose.inverted() @ reference_tpose

# Target
bone.rotation_quaternion @= offset_to_new_pose.inverted()

Hey thanks for your answer!
That solution didn’t work. I have inherit_rotation turned off for each bone, so I think that there is no difference between adding the offset to the current bone rotation or setting it as a new rotation calculated from the tpose.