摘要:快速獲取函數的幫助文檔是閱讀陌生程序的需求,也是學習編程語言的有效方法。對於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