rosen#
- scipy.optimize.rosen(x)[source]#
The Rosenbrock function.
The function computed is:
sum(100.0*(x[1:]-x[:-1]**2.0)**2.0+(1-x[:-1])**2.0)
- Parameters:
- xarray_like
1-D array of points at which the Rosenbrock function is to be computed.
- Returns:
- ffloat
The value of the Rosenbrock function.
See also
Notes
Array API Standard Support
rosenhas experimental support for Python Array API Standard compatiblebackends in addition to NumPy. Please consider testing these featuresby setting an environment variableSCIPY_ARRAY_API=1and providingCuPy, PyTorch, JAX, or Dask arrays as array arguments. The followingcombinations of backend and device (or other capability) are supported.Library
CPU
GPU
NumPy
✅
n/a
CuPy
n/a
✅
PyTorch
✅
✅
JAX
✅
✅
Dask
✅
n/a
SeeSupport for the array API standard for more information.
Examples
>>>importnumpyasnp>>>fromscipy.optimizeimportrosen>>>X=0.1*np.arange(10)>>>rosen(X)76.56
For higher-dimensional input
rosenbroadcasts.In the following example, we use this to plot a 2D landscape.Note thatrosen_hessdoes not broadcast in this manner.>>>importmatplotlib.pyplotasplt>>>frommpl_toolkits.mplot3dimportAxes3D>>>x=np.linspace(-1,1,50)>>>X,Y=np.meshgrid(x,x)>>>ax=plt.subplot(111,projection='3d')>>>ax.plot_surface(X,Y,rosen([X,Y]))>>>plt.show()
