鍍金池/ 問答/數(shù)據(jù)分析&挖掘  Python/ python的包含有的屬性是哪來的

python的包含有的屬性是哪來的

如numpy,我看了github上numpy的包結(jié)構(gòu),發(fā)現(xiàn)numpy就是一個(gè)包,但其__init__.py文件并沒有ones()之類的函數(shù)定義,也沒有對(duì)其的import引用,那么為什么我import numpy之后,可以寫numpy.ones()來調(diào)用這個(gè)函數(shù)呢。

回答
編輯回答
傲寒

numpy/__init__.py里有一句:

from .core import *

然后core/__init__.py里有一句:

from .numeric import *
2018年3月12日 13:51
編輯回答
念舊

用help哦,就可以看到位置在 numpy.core.numeric

help(numpy.ones)
Help on function ones in module numpy.core.numeric:

ones(shape, dtype=None, order='C')
    Return a new array of given shape and type, filled with ones.
    
    Parameters
    ----------
    shape : int or sequence of ints
        Shape of the new array, e.g., ``(2, 3)`` or ``2``.
    dtype : data-type, optional
        The desired data-type for the array, e.g., `numpy.int8`.  Default is
        `numpy.float64`.
    order : {'C', 'F'}, optional
        Whether to store multidimensional data in C- or Fortran-contiguous
        (row- or column-wise) order in memory.
    
    Returns
    -------
    out : ndarray
        Array of ones with the given shape, dtype, and order.
    
    See Also
    --------

clipboard.png

2017年8月18日 08:59