What are the available numpy.loadtxt or numpy.genfromtxt for importing table data with varying datatypes, and what are the available abbreviations for the use (e.g. i32 for integer)?
This post demonstrates the use of conditions, which I was curious if somebody might elaborate on.
loadtxt() function. The loadtxt() function is used to load data from a text file. Each row in the text file must have the same number of values.
Data-type of the resulting array; default: float. If this is a structured data-type, the resulting array will be 1-dimensional, and each row will be interpreted as an element of the array. In this case, the number of columns used must match the number of fields in the data-type.
genfromtxt() function. The genfromtxt() used to load data from a text file, with missing values handled as specified. Each line past the first skip_header lines is split at the delimiter character, and characters following the comments character are discarded.
In addition to np.sctypeDict
, there are these variables:
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]}
Generic info about dtypes
: http://docs.scipy.org/doc/numpy/reference/arrays.dtypes.html
From 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.
And what I didn't realise, is:
The C-like names are associated with character codes, which are shown in the table. Use of the character codes, however, is discouraged.
I doubt the numpy
code/doc base is going anyway anytime soon, so that says it all I guess!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With