{"id":4966,"library":"jacobi","title":"Jacobi: Numerical Derivatives","description":"Jacobi is a lightweight Python library designed for fast and robust computation of generalized Jacobi matrices (numerical derivatives) for arbitrary real analytic mappings. It supports functions with large round-off errors and offers significant speed improvements over other numerical differentiation tools. The current version is 0.9.2, and it typically releases updates as needed.","status":"active","version":"0.9.2","language":"en","source_language":"en","source_url":"https://github.com/HDembinski/jacobi","tags":["numerical derivatives","jacobian","error propagation","scientific computing","numpy"],"install":[{"cmd":"pip install jacobi","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Required for numerical operations and array manipulation.","package":"numpy","optional":false}],"imports":[{"symbol":"jacobi","correct":"from jacobi import jacobi"},{"note":"Used for statistical error propagation based on numerically computed Jacobians.","symbol":"propagate","correct":"from jacobi import propagate"}],"quickstart":{"code":"import numpy as np\nfrom jacobi import jacobi\n\ndef my_function(x):\n    return np.array([np.sin(x[0]) * x[1], np.exp(x[0] + x[1])])\n\n# Point at which to compute the Jacobian\nx0 = np.array([1.0, 2.0])\n\n# Compute the Jacobian matrix and its error estimate\njacobian_matrix, error_estimate = jacobi(my_function, x0)\n\nprint(f\"Function: f(x) = [sin(x[0]) * x[1], exp(x[0] + x[1])]\")\nprint(f\"Point x0: {x0}\")\nprint(f\"Computed Jacobian matrix:\\n{jacobian_matrix}\")\nprint(f\"Error estimate for Jacobian:\\n{error_estimate}\")\n\n# Example with a function returning a scalar and an auxiliary argument\ndef scalar_func(param, x):\n    return np.sin(x * param)\n\naux_param = 0.5\nx_scalar = np.array([np.pi / 2])\nscalar_derivative, scalar_error = jacobi(scalar_func, aux_param, x_scalar)\n\nprint(f\"\\nFunction: g(param, x) = sin(x * param) where param={aux_param}\")\nprint(f\"Point x_scalar: {x_scalar}\")\nprint(f\"Derivative w.r.t. param: {scalar_derivative}\")\nprint(f\"Error estimate: {scalar_error}\")","lang":"python","description":"This quickstart demonstrates how to compute the generalized Jacobi matrix for a vector-valued function and a scalar-valued function with an auxiliary argument using `jacobi.jacobi`. It returns both the derivative and its error estimate."},"warnings":[{"fix":"Verify the mathematical properties of the function being differentiated. For highly non-smooth functions, other techniques like automatic differentiation (if applicable) or specialized numerical methods might be more appropriate.","message":"The `jacobi` function is designed for real analytic mappings. While robust, its accuracy can be affected by highly non-smooth or non-analytic functions. Ensure the function you are differentiating is suitable for numerical differentiation methods.","severity":"gotcha","affected_versions":"All versions"},{"fix":"For functions `f(x)` where `f[i]` only depends on `x[i]`, pass `diagonal=True` as an argument to `jacobi(f, x, diagonal=True)` to optimize performance.","message":"When differentiating a function that returns a 1D array where the Jacobian is known to be diagonal (e.g., an element-wise operation), passing `diagonal=True` to the `jacobi` function can significantly speed up computation. Omitting this for such cases will still yield correct results but might be less efficient.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Where possible, define the function to be differentiated using vectorized `numpy` operations to maximize performance.","message":"The `jacobi` library relies on `numpy` for its numerical operations. Performance can be influenced by how efficiently `numpy` handles the function being differentiated. Vectorized functions tend to perform better.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}