Name
fromstring
Synopsis
fromstring(data
,count
=None,typecode
=Int)
Returns a one-dimensional array a
of shape
(
count
,)
with data copied from the bytes of string
data
. When
count
is None
,
len(
data
)
must be a multiple of
typecode
’s item size, and
a
’s shape is
(len(
data
)/
a
.itemsize( ),)
. When count
is not
None
,
len(
data
)
must be greater than or equal to
count
*
a
.itemsize( )
, and fromstring
ignores
data
’s trailing bytes, if
any.
Together with methods
a
.tostring
and
a
.byteswapped
(covered
in the following section Section 15.6.7), function
fromstring
allows binary input/output of
array
objects. When you need to save arrays and
later reload them, and don’t need to use the saved
form in non-Python programs, it’s simpler and faster
to use module cPickle
, covered in Chapter 11. Many experienced users prefer to use a
portable self-describing file format such as
netCDF
(see http://met-www.cit.cornell.edu/noon/ncmodule.html).
Get Python in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.