Global vector coordinates in local coordinate system of a pose bone

I have a sphere with a location in global coordinates.
I have a bone in pose mode. I can see the local axes of the bone in the Layout.
I am wondering how I can get the coordinates of the sphere in the local coordinate system of my pose bone(using Python).

import bpy
context = bpy.context

sphere =["Roundcube"]
armature =["Armature"]
bone = armature.pose.bones["Bone"]

sphere_world_space_loc = sphere.matrix_world.translation
bone_world_matrix = armature.matrix_world @ bone.matrix

sphere_armature_space_loc = armature.matrix_world.inverted() @ sphere_world_space_loc
sphere_bone_space_loc  = bone_world_matrix.inverted() @ sphere_world_space_loc


Thank you. This is exactly what I wanted.
One more question if possible, when I convert into local space of my bone is the new position measured from the position of the bone(head) or from the global origin?

I don’t quite understand your question, correct me if I didn’t give you an answer you wanted
Bone location in the sidebar is measured in armature space from armature object pivot point

sphere_armature_space_loc - it’s a position (XYZ) of the sphere measured in armature space from armature object pivot point. So it’s the same coordinate system that have bones in the sidebar panel in armature edit mode

sphere_bone_space_loc - it’s a position (XYZ) of the sphere measured in bone space from bone head. You can see axis directions of this coordinate system if you select bone and select “Normal” transform orientation in the header