numpy.source

numpy.source(object, output=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>)[源代码]

将numpy对象的源代码打印或写入文件。

只有用python编写的对象才返回源代码。许多函数和类在C中定义,因此不会返回有用的信息。

参数
objectNumPy 物体

输入对象。这可以是任何对象(函数、类、模块…)。

output文件对象,可选

如果 output 未提供,则源代码打印到屏幕(sys.stdout)。必须使用写入“w”或附加“a”模式创建文件对象。

参见

lookfor, info

实例

>>> np.source(np.interp)                        
In file: /usr/lib/python2.6/dist-packages/numpy/lib/function_base.py
def interp(x, xp, fp, left=None, right=None):
    """.... (full docstring printed)"""
    if isinstance(x, (float, int, number)):
        return compiled_interp([x], xp, fp, left, right).item()
    else:
        return compiled_interp(x, xp, fp, left, right)

只有用python编写的对象才返回源代码。

>>> np.source(np.array)                         
Not available for this object.