Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

SciPy · Function

optimize.minimize

scipy.optimize.minimize minimizes a scalar function of one or more variables. Choose a solver and optionally provide derivatives, bounds, constraints, tolerances, callbacks, and solver-specific options.

How it works

minimize selects a numerical solver to reduce a scalar objective from an initial vector. The objective receives the current vector and optional fixed arguments; derivatives, bounds, constraints, tolerances, callbacks, and solver-specific options can be supplied to control the optimization.

Syntax

scipy.optimize.minimize(fun, x0, args=(), method=None, jac=None, hess=None, hessp=None, bounds=None, constraints=(), tol=None, callback=None, options=None)

Parameters

NameTypeDescription
funcallableObjective callable with signature fun(x, *args) -> float.
x0ndarray, shape (n,)Initial guess: a one-dimensional array of length n.
argstuple, optionalExtra arguments passed to fun and derivative functions.
methodstr or callable, optionalSolver name or callable.
jaccallable, bool or str, optionalGradient of the objective; callable, Boolean, or finite-difference specification depending on method.
hesscallable, str or HessianUpdateStrategy, optionalHessian of the objective, supplied as a callable, finite-difference scheme, or HessianUpdateStrategy where supported.
hesspcallable, optionalHessian-vector product callable.
boundssequence or Bounds, optionalBounds for variables.
constraints{Constraint, dict} or List of {Constraint, dict}, optionalEquality and inequality constraints.
tolfloat, optionalTolerance for termination.
callbackcallable, optionalCallback invoked during optimization.
optionsdict, optionalSolver-specific options.

Returns

OptimizeResult containing the solution, objective value, success status, termination message, and method-dependent diagnostic fields.

Key points

  • Use minimize when the objective is scalar-valued and depends on one or more variables.
  • fun is the callable defining the quantity the solver attempts to reduce.
  • method identifies the algorithm, or accepts a callable for a custom solver.
  • args carries fixed parameters needed by fun, jac, and hess.

Example: Minimize a quadratic function

import numpy as np
from scipy.optimize import minimize

def objective(x):
    return (x[0] - 2.0) ** 2 + (x[1] + 1.0) ** 2

result = minimize(objective, x0=np.array([0.0, 0.0]), method="BFGS")
print(result.x)
print(result.fun)

Defines a two-variable quadratic objective and minimizes it from an initial guess using BFGS.

When to use it

Fit model parameters by minimizing a scalar loss function.

Parameter estimation

Find a minimum while enforcing bounds or equality and inequality constraints.

Constrained optimization

Optimize several continuous design variables from an initial candidate.

Numerical design

Interview questions

QWhat problem does scipy.optimize.minimize solve?

minimize solves scalar minimization problems with one or more variables. It takes an objective callable and an initial vector, then returns an OptimizeResult containing the solution and diagnostic information.

Follow-up: How would you pass fixed data to the objective? Supply it through args, whose tuple is forwarded to the objective and derivative callables.

QHow is the solver selected?

method chooses the optimization algorithm and can be a solver name or a callable. If omitted, SciPy selects a method based on the supplied bounds and constraints.

Follow-up: What must a custom method accept? It is called with fun, x0, args, keyword parameters, and the contents of options.

QWhat derivative and feasibility controls does minimize support?

jac supplies the objective gradient, while hess supplies a Hessian and hessp supplies Hessian-vector products for methods that use second-order information. These derivatives can improve efficiency or are required by particular methods.

Follow-up: When are bounds and constraints appropriate? Use bounds for per-variable intervals and constraints for equality or inequality relationships among variables.

  • scipy.optimize.OptimizeResult
  • scipy.optimize.minimize_scalar
  • scipy.optimize.Bounds
  • scipy.optimize.LinearConstraint
  • scipy.optimize.NonlinearConstraint
  • scipy.optimize.show_options

Source: Minimize. Checked 2026-10-15.