2017-03-02 31 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的子類型。

相關問題