Get a full numeric z-depth from a rendered image
You can obtain depth values by plugin the depths calculated at render time to a "viewer node" in the compositor.

First make sure the rendering uses z (should be set by default):



Setup the viewer node in the compositor:



Render the image (F12).

Now you can have data from Python (principles only below):

img=bpy.data.images['Viewer Node'] # get the image corresponding to the viewer node

img.size # the image size width=img.size[0] height=img.size[1]

img.pixels # raw vector of pixels representing the depths. You'll have to reshape it to obtain a matrix, using numpy or by other means


What's remaining is to write it to a file (which is no more related to Blender).

Hope that helps.