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

SciPy · Function

minimize

Minimizes a scalar function of one or more variables using a selectable optimization method. It supports derivatives, bounds, constraints, tolerances, callbacks, and method-specific options.

How it works

minimize searches for an argument vector that produces a small value of a scalar objective. It accepts an initial point, optionally selects a solver and derivatives, and returns an OptimizeResult containing the solution, objective value, and solver status information.

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: fun(x, *args) -> float.
x0ndarrayInitial guess; a real one-dimensional array of shape (n,).
argstuple, optionalExtra arguments passed to the objective and derivative functions.
methodstr or callable, optionalSolver name or custom minimization callable.
jaccallable, bool, or str, optionalJacobian specification for the objective.
hesscallable or str, optionalHessian specification or Hessian-update strategy.
hesspcallable, optionalHessian-vector product callable.
boundssequence or Bounds, optionalBounds on variables.
constraintsConstraint or sequence, optionalConstraints definition.
tolfloat, optionalSolver termination tolerance.
optionsdict, optionalMethod-specific options.
callbackcallable, optionalProgress callback.

Returns

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

Key points

  • Use minimize to find variables that reduce a scalar objective function.
  • fun is a callable receiving x and optional fixed arguments and returning one scalar value.
  • args supplies fixed values forwarded to fun and derivative callables.
  • method chooses the optimization algorithm by name or through a custom callable.
  • Bounds and constraints can be provided when the problem restricts feasible variable values.

Common mistakes

  • If method is omitted, SciPy chooses a solver based on whether bounds or constraints are present; for an unconstrained problem, the default is BFGS.

Example: Minimize a quadratic objective

import numpy as np
from scipy.optimize import minimize

result = minimize(lambda x: (x[0] - 3)**2 + (x[1] + 1)**2,
                  x0=np.array([0.0, 0.0]), method="BFGS")
print(result.x)
print(result.fun)

Minimizes a two-variable quadratic from an initial guess and prints the estimated minimizer and objective value.

When to use it

Unconstrained numerical optimization

Find parameters that minimize a differentiable loss without constraints.

Bounded and constrained fitting

Optimize parameters subject to variable limits or feasibility conditions.

Derivative-assisted optimization

Use an analytic gradient or Hessian to improve solver performance.

Interview questions

QWhat are the required inputs to minimize?

fun receives a one-dimensional parameter array and any values supplied through args, and it must return a scalar objective value. x0 supplies the initial guess for the independent variables.

Follow-up: How would you provide a gradient? Pass jac as a callable returning the gradient, or use the documented boolean shortcut when fun returns both the objective and gradient.

QHow does method affect minimize?

method selects the optimization algorithm and can be a method name or a callable. If it is omitted, SciPy selects an appropriate method from the presence of bounds and constraints.

Follow-up: Which solver is used for an unconstrained problem when method is omitted? BFGS is the default in that case.

QWhat does minimize return?

The return value is an OptimizeResult, with fields such as x for the solution, fun for the objective value, success for the termination status, and message for a human-readable explanation. Solver-specific fields may also be present.

Follow-up: How should a caller detect failure? Check success and inspect message rather than assuming that a returned x indicates successful convergence.

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

Source: Minimize. Checked 2026-10-15.