numpy.fromstring
-
numpy.fromstring(string, dtype=float, count=-1, sep='')
-
A new 1-D array initialized from text data in a string.
- Parameters
-
-
stringstr
-
A string containing the data.
-
dtypedata-type, optional
-
The data type of the array; default: float. For binary input data, the data must be in exactly this format. Most builtin numeric types are supported and extension types may be supported.
New in version 1.18.0: Complex dtypes.
-
countint, optional
-
Read this number of
dtype
elements from the data. If this is negative (the default), the count will be determined from the length of the data. -
sepstr, optional
-
The string separating numbers in the data; extra whitespace between elements is also ignored.
Deprecated since version 1.14: Passing
sep=''
, the default, is deprecated since it will trigger the deprecated binary mode of this function. This mode interpretsstring
as binary bytes, rather than ASCII text with decimal numbers, an operation which is better speltfrombuffer(string, dtype, count)
. Ifstring
contains unicode text, the binary mode offromstring
will first encode it into bytes using either utf-8 (python 3) or the default encoding (python 2), neither of which produce sane results.
-
- Returns
-
-
arrndarray
-
The constructed array.
-
- Raises
-
- ValueError
-
If the string is not the correct size to satisfy the requested
dtype
andcount
.
See also
Examples
>>> np.fromstring('1 2', dtype=int, sep=' ') array([1, 2]) >>> np.fromstring('1, 2', dtype=int, sep=',') array([1, 2])
© 2005–2020 NumPy Developers
Licensed under the 3-clause BSD License.
https://numpy.org/doc/1.19/reference/generated/numpy.fromstring.html