Get help of python and python package function/获取python及python包函数的帮助文档

摘要:快速获取函数的帮助文档是阅读陌生程序的需求,也是学习编程语言的有效方法。对于python和python包,均有这样的支持。这里以numpy为例,说明其获取帮助的方法,其一使用包提供的帮助函数,其二查找帮助文档,当然还有其三万能的google。

Method 1: using help function or method

For general python function, help() function return the help of general python functions.

e.g.

help(max)

For numpy methods (functions), np.info() method return the help of numpy methods (functions).

e.g.

import numpy as np

np.info(np.maximum)

 

Method 2:using reference doc

search in ‘Index’ of reference doc

https://docs.scipy.org/doc/numpy/numpy-ref-1.14.5.pdf

e.g. maximum in page 826 of reference book

Function:

numpy.maximum(x1, x2, /, out=None, *, where=True, casting=’same_kind’, order=’K’, dtype=None, subok=True[, signature, extobj]) = <ufunc ‘maximum’>

Description:

Element-wise maximum of array elements.

Compare two arrays and returns a new array containing the element-wise maxima. If one of the elements being compared is a NaN, then that element is returned. If both elements are NaNs then the first is returned. The latter distinction is important for complex NaNs, which are defined as at least one of the real or imaginary parts being a NaN. The net effect is that NaNs are propagated.

Example:

data = numpy.random.randn(10,20)

data_relu = numpy.maximum(data, 0)

# get max of data and 0

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章