Documentation¶
Due to the length of this book, it is impossible for us to introduce all MXNet functions and classes. The API documentation and additional tutorials and examples provide plenty of documentation beyond the book.
Finding all the functions and classes in the module¶
In order to know which functions and classes can be called in a module,
we use the dir
function. For instance we can query all the members
or properties in the nd.random
module.
In [1]:
from mxnet import nd
print(dir(nd.random))
['NDArray', '_Null', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '_internal', '_random_helper', 'current_context', 'exponential', 'gamma', 'generalized_negative_binomial', 'multinomial', 'negative_binomial', 'normal', 'numeric_types', 'poisson', 'shuffle', 'uniform']
Generally speaking, we can ignore functions that start and end with
__
(special objects in Python) or functions that start with a single
_
(usually internal functions). According to the remaining member
names, we can then hazard a guess that this module offers a generation
method for various random numbers, including uniform distribution
sampling (uniform
), normal distribution sampling (normal
), and
Poisson sampling (poisson
).
Finding the usage of specific functions and classes¶
For specific function or class usage, we can use the help
function.
Let’s take a look at the usage of the
ones_like, such as the NDArray function as an example.
In [2]:
help(nd.ones_like)
Help on function ones_like:
ones_like(data=None, out=None, name=None, **kwargs)
Return an array of ones with the same shape and type
as the input array.
Examples::
x = [[ 0., 0., 0.],
[ 0., 0., 0.]]
ones_like(x) = [[ 1., 1., 1.],
[ 1., 1., 1.]]
Parameters
----------
data : NDArray
The input
out : NDArray, optional
The output NDArray to hold the result.
Returns
-------
out : NDArray or list of NDArrays
The output of this function.
From the documentation, we learned that the ones_like
function
creates a new one with the same shape as the NDArray and an element of
1. Let’s verify it:
In [3]:
x = nd.array([[0, 0, 0], [2, 2, 2]])
y = x.ones_like()
y
Out[3]:
[[1. 1. 1.]
[1. 1. 1.]]
<NDArray 2x3 @cpu(0)>
In the Jupyter notebook, we can use ?
to display the document in
another window. For example, nd.random.uniform?
will create content
that is almost identical to help(nd.random.uniform)
, but will be
displayed in an extra window. In addition, if we use two
nd.random.uniform??
, the function implementation code will also be
displayed.
API Documentation¶
For further details on the API details check the MXNet website at http://mxnet.apache.org/. You can find the details under the appropriate headings (also for programming languages other than Python).
Exercise¶
Check out the documentation for ones_like
and for autograd
.