gpt4 book ai didi

python - numpy:int 是一个 basestring?

转载 作者:太空宇宙 更新时间:2023-11-03 10:55:02 24 4
gpt4 key购买 nike

为什么 numpy 数字类型是 basestring 的子类型?

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

最佳答案

basestring 不是 dtype 或可理智地转换为 dtype,并且 issubdtype 没有错误处理来识别这一点。 It calls numpy.dtypebasestring 上获取 dtype,并且由于 numpy.dtype 看到输入是它不理解的 Python 类型对象,因此生成的 dtype 是对象 dtype。其余逻辑将每个数据类型视为对象数据类型的子类型。

关于python - numpy:int 是一个 basestring?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42568182/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com