# Transforming armature bone by matrix of another bone in pose mode

I am attempting to move an armature bone in edit mode by the inverted matrix of another bone in pose mode. My reasoning for doing this is because I have joined two armatures and have lined the bones of the second armature up with the first armature while the first armature was in pose mode (made it much easier). So what I'm attempting to do is keep the same location/rotation offsets between the two, but transform the second armature's bones to be relative to the default position of the first armature. I hope that makes sense. I believe this is possible, but I'm not sure exactly which matrices I need to be applying to get the desired effect as my below script does not provide desired result. I feel like I'm missing some vital key element...might anyone know what that is?

import bpy
from mathutils import Vector, Matrix
import numpy as np

matFilePath = 'Z:\\models\\myfps\\weapons\\pretty\\arms\\script\\mat.txt'

def convert_matrix_to_string(some_matrix):
# omitted for brevity

def convert_file_to_matrix(some_path):
# omitted for brevity

# select the bone in pose mode and run this to save to matFilePath
#for b in bpy.context.selected_pose_bones:
#    f = open(matFilePath, "w")
#    f.write(convert_matrix_to_string(b.matrix))
#    f.close()

# load in the matrix from file
hand_pose_mat = convert_file_to_matrix(matFilePath)

# apply inversion of matrix to bone
for b in bpy.context.selected_bones:
b.transform(hand_pose_mat.inverted())


The below images should assist in explaining what I am attempting to accomplish:

for b in bpy.context.selected_bones: