2017-03-02 73 views
4

numpy数值类型是怎么来的basestring的子类型?numpy:int是一个基础字符串?

for nptype in [np.int32, np.int64, np.integer, np.float]: 
    for stype in [str, basestring, unicode]: 
     print nptype, stype, np.issubdtype(nptype,stype) 
<type 'numpy.int32'> <type 'str'> False 
<type 'numpy.int32'> <type 'basestring'> True 
<type 'numpy.int32'> <type 'unicode'> False 
<type 'numpy.int64'> <type 'str'> False 
<type 'numpy.int64'> <type 'basestring'> True 
<type 'numpy.int64'> <type 'unicode'> False 
<type 'numpy.integer'> <type 'str'> False 
<type 'numpy.integer'> <type 'basestring'> True 
<type 'numpy.integer'> <type 'unicode'> False 
<type 'float'> <type 'str'> False 
<type 'float'> <type 'basestring'> True 
<type 'float'> <type 'unicode'> False 

回答

3

basestring不是D型或三立可转换到D型,而issubdtype没有错误处理认识到这一点。 It calls numpy.dtypebasestring上得到一个dtype,并且由于numpy.dtype发现输入是一个它不理解的Python类型对象,所以得到的dtype是对象dtype。逻辑的其余部分将每个dtype都视为对象dtype的子类型。

相关问题