<commit_before>\section{\module{array} ---
         Efficient arrays of numeric values}

\declaremodule{builtin}{array}
\modulesynopsis{Efficient arrays of uniformly typed numeric values.}


This module defines an object type which can efficiently represent
an array of basic values: characters, integers, floating point
numbers.  Arrays\index{arrays} are sequence types and behave very much
like lists, except that the type of objects stored in them is
constrained.  The type is specified at object creation time by using a
\dfn{type code}, which is a single character.  The following type
codes are defined:

\begin{tableiii}{c|l|c}{code}{Type code}{C Type}{Minimum size in bytes}
\lineiii{'c'}{character}{1}
\lineiii{'b'}{signed int}{1}
\lineiii{'B'}{unsigned int}{1}
\lineiii{'u'}{Unicode character}{2}
\lineiii{'h'}{signed int}{2}
\lineiii{'H'}{unsigned int}{2}
\lineiii{'i'}{signed int}{2}
\lineiii{'I'}{unsigned int}{2}
\lineiii{'l'}{signed int}{4}
\lineiii{'L'}{unsigned int}{4}
\lineiii{'f'}{float}{4}
\lineiii{'d'}{double}{8}
\end{tableiii}

The actual representation of values is determined by the machine
architecture (strictly speaking, by the C implementation).  The actual
size can be accessed through the \member{itemsize} attribute.  The values
stored  for \code{'L'} and \code{'I'} items will be represented as
Python long integers when retrieved, because Python's plain integer
type cannot represent the full range of C's unsigned (long) integers.


The module defines the following type:

\begin{funcdesc}{array}{typecode\optional{, initializer}}
Return a new array whose items are restricted by \var{typecode},
and initialized from the optional \var{initializer} value, which
must be a list or a string.  The list or string is passed to the
new array's \method{fromlist()}, \method{fromstring()}, or
\method{fromunicode()} method (see below) to add initial items to
the array.
\end{funcdesc}

\begin{datadesc}{ArrayType}
Obsolete alias for \function{array}.
\end{datadesc}


Array objects support the ordinary sequence operations of
indexing, slicing, concatenation, and multiplication.  The
following data items and methods are also supported:

\begin{memberdesc}[array]{typecode}
The typecode character used to create the array.
\end{memberdesc}

\begin{memberdesc}[array]{itemsize}
The length in bytes of one array item in the internal representation.
\end{memberdesc}


\begin{methoddesc}[array]{append}{x}
Append a new item with value \var{x} to the end of the array.
\end{methoddesc}

\begin{methoddesc}[array]{buffer_info}{}
Return a tuple \code{(\var{address}, \var{length})} giving the current
memory address and the length in elements of the buffer used to hold
array's contents.  The size of the memory buffer in bytes can be
computed as \code{\var{array}.buffer_info()[1] *
\var{array}.itemsize}.  This is occasionally useful when working with
low-level (and inherently unsafe) I/O interfaces that require memory
addresses, such as certain \cfunction{ioctl()} operations.  The
returned numbers are valid as long as the array exists and no
length-changing operations are applied to it.

\note{When using array objects from code written in C or
\Cpp{} (the only way to effectively make use of this information), it
makes more sense to use the buffer interface supported by array
objects.  This method is maintained for backward compatibility and
should be avoided in new code.  The buffer interface is documented in
the \citetitle[../api/newTypes.html]{Python/C API Reference Manual}.}
\end{methoddesc}

\begin{methoddesc}[array]{byteswap}{}
``Byteswap'' all items of the array.  This is only supported for
values which are 1, 2, 4, or 8 bytes in size; for other types of
values, \exception{RuntimeError} is raised.  It is useful when reading
data from a file written on a machine with a different byte order.
\end{methoddesc}

\begin{methoddesc}[array]{count}{x}
Return the number of occurences of \var{x} in the array.
\end{methoddesc}

\begin{methoddesc}[array]{extend}{a}
Append array items from \var{a} to the end of the array.
\end{methoddesc}<commit_msg>Fix up the documentation of the type codes to give both the C and Python types for each code, and give the actual C types.<commit_after>\section{\module{array} ---
         Efficient arrays of numeric values}

\declaremodule{builtin}{array}
\modulesynopsis{Efficient arrays of uniformly typed numeric values.}


This module defines an object type which can efficiently represent
an array of basic values: characters, integers, floating point
numbers.  Arrays\index{arrays} are sequence types and behave very much
like lists, except that the type of objects stored in them is
constrained.  The type is specified at object creation time by using a
\dfn{type code}, which is a single character.  The following type
codes are defined:

\begin{tableiv}{c|l|l|c}{code}{Type code}{C Type}{Python Type}{Minimum size in bytes}
  \lineiv{'c'}{char}          {character}        {1}
  \lineiv{'b'}{signed char}   {int}              {1}
  \lineiv{'B'}{unsigned char} {int}              {1}
  \lineiv{'u'}{Py_UNICODE}    {Unicode character}{2}
  \lineiv{'h'}{signed short}  {int}              {2}
  \lineiv{'H'}{unsigned short}{int}              {2}
  \lineiv{'i'}{signed int}    {int}              {2}
  \lineiv{'I'}{unsigned int}  {long}             {2}
  \lineiv{'l'}{signed long}   {int}              {4}
  \lineiv{'L'}{unsigned long} {long}             {4}
  \lineiv{'f'}{float}         {float}            {4}
  \lineiv{'d'}{double}        {float}            {8}
\end{tableiv}

The actual representation of values is determined by the machine
architecture (strictly speaking, by the C implementation).  The actual
size can be accessed through the \member{itemsize} attribute.  The values
stored  for \code{'L'} and \code{'I'} items will be represented as
Python long integers when retrieved, because Python's plain integer
type cannot represent the full range of C's unsigned (long) integers.


The module defines the following type:

\begin{funcdesc}{array}{typecode\optional{, initializer}}
Return a new array whose items are restricted by \var{typecode},
and initialized from the optional \var{initializer} value, which
must be a list or a string.  The list or string is passed to the
new array's \method{fromlist()}, \method{fromstring()}, or
\method{fromunicode()} method (see below) to add initial items to
the array.
\end{funcdesc}

\begin{datadesc}{ArrayType}
Obsolete alias for \function{array}.
\end{datadesc}


Array objects support the ordinary sequence operations of
indexing, slicing, concatenation, and multiplication.  When using
slice assignment, the assigned value must be an array object with the
same type code; in all other cases, \exception{TypeError} is raised.
Array objects also implement the buffer interface, and may be used
wherever buffer objects are supported.

The following data items and methods are also supported:

\begin{memberdesc}[array]{typecode}
The typecode character used to create the array.
\end{memberdesc}

\begin{memberdesc}[array]{itemsize}
The length in bytes of one array item in the internal representation.
\end{memberdesc}


\begin{methoddesc}[array]{append}{x}
Append a new item with value \var{x} to the end of the array.
\end{methoddesc}

\begin{methoddesc}[array]{buffer_info}{}
Return a tuple \code{(\var{address}, \var{length})} giving the current
memory address and the length in elements of the buffer used to hold
array's contents.  The size of the memory buffer in bytes can be
computed as \code{\var{array}.buffer_info()[1] *
\var{array}.itemsize}.  This is occasionally useful when working with
low-level (and inherently unsafe) I/O interfaces that require memory
addresses, such as certain \cfunction{ioctl()} operations.  The
returned numbers are valid as long as the array exists and no
length-changing operations are applied to it.

\note{When using array objects from code written in C or
\Cpp{} (the only way to effectively make use of this information), it
makes more sense to use the buffer interface supported by array
objects.  This method is maintained for backward compatibility and
should be avoided in new code.  The buffer interface is documented in
the \citetitle[../api/newTypes.html]{Python/C API Reference Manual}.}
\end{methoddesc}

\begin{methoddesc}[array]{byteswap}{}
``Byteswap'' all items of the array.  This is only supported for
values which are 1, 2, 4, or 8 bytes in size; for other types of
values, \exception{RuntimeError} is raised.  It is useful when reading
data from a file written on a machine with a different byte order.
\end{methoddesc}

\begin{methoddesc}[array]{count}{x}
Return the number of occurences of \var{x} in the array.
\end{methoddesc}

\begin{methoddesc}[array]{extend}{a}
Append array items from \var{a} to the end of the array.  The two
arrays must have \emph{exactly} the same type code; if not,
\exception{TypeError} will be raised.
\end{methoddesc}
{'fraction_non_alphanumeric': 0.0999664916787669, 'fraction_numerical': 0.0037976097397520382, 'mean_word_length': 4.568407960199005, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1636904', 'n_tokens_mistral': 2572, 'n_tokens_neox': 2510, 'n_words': 1114}