zoukankan      html  css  js  c++  java
  • 查询文档

    本博文来自于 《动手学深度学习》 本博文只是记录学习笔记,方便日后查缺补漏,如有侵权,联系删除

    查阅文档

    查找模块里的所有函数和类

    当我们想知道一个模块里面提供了哪些可以调用的函数和类的时候,可以使用dir函数。下面我们打印nd.random模块中所有的成员或属性。

    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', 'exponential_like', 'gamma', 'gamma_like', 'generalized_negative_binomial', 'generalized_negative_binomial_like', 'multinomial', 'negative_binomial', 'negative_binomial_like', 'normal', 'normal_like', 'numeric_types', 'poisson', 'poisson_like', 'randint', 'randn', 'shuffle', 'uniform', 'uniform_like']
    

    通常我们可以忽略掉由__开头和结尾的函数(Python的特别对象)或者由_开头的函数(一般为内部函数)。通过其余成员的名字我们大致猜测出这个模块提供了各种随机数的生成方法,包括从均匀分布采样(uniform)、从正态分布采样(normal)、从泊松分布采样(poisson)等。

    查找特定函数和类的使用

    想了解某个函数或者类的具体用法时,可以使用help函数。让我们以NDArray中的ones_like函数为例,查阅它的用法。

    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.
    

    从文档信息我们了解到,ones_like函数会创建和输入NDArray形状相同且元素为1的新NDArray。我们可以验证一下。

    x = nd.array([[0, 0, 0], [2, 2, 2]])
    y = x.ones_like()
    y
    
    [[1. 1. 1.]
     [1. 1. 1.]]
    <NDArray 2x3 @cpu(0)>
    

    在Jupyter记事本里,我们可以使用?来将文档显示在另外一个窗口中。例如,使用nd.random.uniform?将得到与help(nd.random.uniform)几乎一样的内容,但会显示在额外窗口里。此外,如果使用nd.random.uniform??,那么会额外显示该函数实现的代码。

    nd.random.uniform?
    

    图片

    nd.random.uniform??
    

    图片

    在MXNet网站上查阅

    读者也可以在MXNet的网站上查阅相关文档。访问MXNet网站 https://mxnet.apache.org/ (如图2.1所示),点击网页顶部的下拉菜单“API”可查阅各个前端语言的接口。此外,也可以在网页右上方含“Search”字样的搜索框中直接搜索函数或类名称。

    MXNet官方网站

    图2.2展示了MXNet网站上有关ones_like函数的文档。

    MXNet网站上有关函数的文档

    小结

    • 遇到不熟悉的MXNet API时,可以主动查阅它的相关文档。
    • 查阅MXNet文档可以使用dirhelp函数,或访问MXNet官方网站。
    不一定每天 code well 但要每天 live well
  • 相关阅读:
    CentOS系统下的数据盘挂载
    在iOS微信浏览器中自动播放HTML5 audio(音乐)的2种正确方式
    C盘占用过满问题
    大量ECAgent报错
    微信电脑版不断崩溃
    java web 在tomcat没有正常输出
    文件解压缩失败
    在myeclipse安装beyond插件
    限时免费 GoodSync 10 同步工具【转】
    soapUI的bug切换版本解决
  • 原文地址:https://www.cnblogs.com/geekfx/p/13875494.html
Copyright © 2011-2022 走看看