import scipy
def f(x):
return x**2
= 1
guess = scipy.optimize.minimize(f,x0=1) result
Appendix A — Documentation (Spyder)
In this chapter we explain how to access the interval documentation of Python within Spyder, which you are allowed to use during the exam.
If you import a package, such as NumPy, and use a function from it, you can inspect the documentation of the function using the following steps:
- Select the function name with your cursor;
- Right-click with your mouse on the selected function name;
- Choose “Inspect current object”.
Instead of selecting the function name, you can also click with your cursor at the beginning of the function name. Furthermore, the keyboard shortcut Ctrl
i
allows you to inspect the object directly, without right-clicking with the mouse.
np.ones()
functionThe documentation of the function appears in the ‘Help’ pane on the top-right. You can scroll through it to see what the function input- and output arguments are, and there are often also examples at the bottom.
A.1 Inspecting subpackages
If you want to inspect functions that are part of a subpackage, it is recommended to import the subpackage under an alias, otherwise Python might not automatically load the documentation as well.
minimize()
function from SciPy’s optimize
module.If you only load the subpackage, you might not be able to see the documentation. For example, trying to inspect minimize()
by selecting minimize
in the two codes below (in Spyder) might not work.
import scipy.optimize
def f(x):
return x**2
= 1
guess = scipy.optimize.minimize(f,x0=1) result
As a second example, if you want to inspect a random variable from the stats
subpackage of SciPy, it is best to import this subpackage under an alias. In the screenshot below we choose the name statistics
as alias.
gamma()
random variable object from SciPy’s stats
module.A.2 Other methods
If you cannot access the documentation of a function by inspecting it, you can also access the plain text of the documentation in the console. Do this by typing ?[function_of_interest]
where you replace [function_of_interest]
by the function (of a subpackage) that you want to have the documentation of.
For example, ?scipy.optimize.minimize
should give you the documentation of the minimize()
function, as illustrated in the figure below. Note that if you want to leave the documentation in the console, you have to press “Q”.
It is recommended to first run your file (in which you imported a package) before you try to access its documentation in the console.
scipy.optimize.minimize()
in console.