NumPy的loadtxt()和genfromtxt的'dtype'有哪些可用的数据类型?

2024-05-13 14:46:31 发布

您现在位置:Python中文网/ 问答频道 /正文

对于导入具有不同数据类型的表数据,可用的numpy.loadtxtnumpy.genfromtxt是什么,以及可用的缩写是什么(例如,i32表示整数)?

This post演示了条件的使用,我很好奇是否有人可以详细说明。


Tags: 数据numpy整数this条件post数据类型i32
3条回答

关于dtypeshttp://docs.scipy.org/doc/numpy/reference/arrays.dtypes.html的一般信息

来自http://docs.scipy.org/doc/numpy/reference/arrays.scalars.html#arrays-scalars-built-in

In NumPy, there are 24 new fundamental Python types to describe different types of scalars. These type descriptors are mostly based on the types available in the C language that CPython is written in, with several additional types compatible with Python’s types.

我没有意识到的是:

The C-like names are associated with character codes, which are shown in the table. Use of the character codes, however, is discouraged.

我怀疑numpy代码/文档库是否会在短期内运行,所以我猜这就是全部!

for k, v in np.sctypeDict.iteritems(): print '{0:14s} : {1:40s}'.format(str(k), v)

Q              : <type 'numpy.uint64'>      
U              : <type 'numpy.unicode_'>
a              : <type 'numpy.string_'>

等等

除了np.sctypeDict,还有以下变量:

In [141]: np.typecodes
Out[141]: 
{'All': '?bhilqpBHILQPefdgFDGSUVOMm',
 'AllFloat': 'efdgFDG',
 'AllInteger': 'bBhHiIlLqQpP',
 'Character': 'c',
 'Complex': 'FDG',
 'Datetime': 'Mm',
 'Float': 'efdg',
 'Integer': 'bhilqp',
 'UnsignedInteger': 'BHILQP'}

In [143]: np.sctypes
Out[143]: 
{'complex': [numpy.complex64, numpy.complex128, numpy.complex192],
 'float': [numpy.float16, numpy.float32, numpy.float64, numpy.float96],
 'int': [numpy.int8, numpy.int16, numpy.int32, numpy.int32, numpy.int64],
 'others': [bool, object, str, unicode, numpy.void],
 'uint': [numpy.uint8, numpy.uint16, numpy.uint32, numpy.uint32, numpy.uint64]}

相关问题 更多 >