3d python coefficient function