"array" --- 高效率的數值型陣列
******************************

======================================================================

這個模組定義了一個物件型別，可以簡潔的表達一個包含基本數值的陣列：字元
、整數、浮點數。陣列是一個非常類似 list（串列）的序列型別，除了陣列會
限制儲存的物件型別。在建立陣列時可以使用一個字元的 *type code* 來指定
儲存的資料型別。以下為有被定義的 type codes：

+-------------+----------------------+---------------------+-------------------------+---------+
| Type code   | C Type               | Python Type         | 所需的最小位元組        | 註解    |
|             |                      |                     | (bytes)                 |         |
|=============|======================|=====================|=========================|=========|
| "'b'"       | signed char          | int                 | 1                       |         |
+-------------+----------------------+---------------------+-------------------------+---------+
| "'B'"       | unsigned char        | int                 | 1                       |         |
+-------------+----------------------+---------------------+-------------------------+---------+
| "'u'"       | wchar_t              | Unicode character   | 2                       | (1)     |
+-------------+----------------------+---------------------+-------------------------+---------+
| "'h'"       | signed short         | int                 | 2                       |         |
+-------------+----------------------+---------------------+-------------------------+---------+
| "'H'"       | unsigned short       | int                 | 2                       |         |
+-------------+----------------------+---------------------+-------------------------+---------+
| "'i'"       | signed int           | int                 | 2                       |         |
+-------------+----------------------+---------------------+-------------------------+---------+
| "'I'"       | unsigned int         | int                 | 2                       |         |
+-------------+----------------------+---------------------+-------------------------+---------+
| "'l'"       | signed long          | int                 | 4                       |         |
+-------------+----------------------+---------------------+-------------------------+---------+
| "'L'"       | unsigned long        | int                 | 4                       |         |
+-------------+----------------------+---------------------+-------------------------+---------+
| "'q'"       | signed long long     | int                 | 8                       |         |
+-------------+----------------------+---------------------+-------------------------+---------+
| "'Q'"       | unsigned long long   | int                 | 8                       |         |
+-------------+----------------------+---------------------+-------------------------+---------+
| "'f'"       | float                | float               | 4                       |         |
+-------------+----------------------+---------------------+-------------------------+---------+
| "'d'"       | double               | float               | 8                       |         |
+-------------+----------------------+---------------------+-------------------------+---------+

註解：

1. 根據平台的不同，它有可能是 16 位元或者 32 位元。

   在 3.9 版的變更: "array('u')" now uses "wchar_t" as C type instead
   of deprecated "Py_UNICODE". This change doesn't affect its behavior
   because "Py_UNICODE" is alias of "wchar_t" since Python 3.3.

   自從版本 3.3 後不推薦使用，將會自版本 4.0 中移除。.

實際上數值的表示方法是被機器的架構所決定（更精準地說，被 C 的實作方法
決定）。實際的大小可以透過 "array.itemsize" 屬性存取。

這個模組定義了以下項目：

array.typecodes

   一個包含所有可用的 type codes 的字串。

這個模組定義了下方的型別：

class array.array(typecode[, initializer])

   A new array whose items are restricted by *typecode*, and
   initialized from the optional *initializer* value, which must be a
   "bytes" or "bytearray" object, a Unicode string, or iterable over
   elements of the appropriate type.

   If given a "bytes" or "bytearray" object, the initializer is passed
   to the new array's "frombytes()" method; if given a Unicode string,
   the initializer is passed to the "fromunicode()" method; otherwise,
   the initializer's iterator is passed to the "extend()" method to
   add initial items to the array.

   陣列支援常見的序列操作，包含索引 (indexing)、切片 (slicing)、串接
   (concatenation)、相乘 (multiplication) 等。當使用切片進行賦值時，賦
   值的陣列必須具備相同的 type code，其他型別的數值將導致 "TypeError"
   。陣列同時也實作了緩衝區介面，可以在任何支援 *bytes-like objects*
   的地方使用。

   引發稽核事件 (auditing event) "array.__new__" 並帶入引數 "typecode"
   、"initializer"。

   typecode

      typecode 字元被用在建立陣列時。

   itemsize

      陣列當中的一個元素在內部需要的位元組長度。

   append(x)

      新增一個元素 *x* 到陣列的最尾端。

   buffer_info()

      回傳一個 tuple "(address, length)" 表示當前的記憶體位置和陣列儲
      存元素的緩衝區記憶體長度。緩衝區的長度單位是位元組，並可以用
      "array.buffer_info()[1] * array.itemsize" 計算得到。這偶爾會在底
      層操作需要記憶體位置的輸出輸入時很有用，例如 "ioctl()" 指令。只
      要陣列存在且沒有使用任何更改長度的操作時，回傳的數值就有效。

      備註:

        當使用來自 C 或 C++ 程式碼（這是唯一使得這個資訊有效的途徑）的
        陣列物件時，更適當的做法是使用陣列物件支援的緩衝區介面。這個方
        法維護了向後兼容性，並應該在新的程式碼中避免。關於緩衝區介面的
        文件在緩衝協定 (Buffer Protocol)。

   byteswap()

      "Byteswap" 所有陣列中的物件。這只有支援物件長度為 1、2、4 或 8
      位元組的陣列，其他型別的值會導致 "RuntimeError"。這在從機器讀取
      位元順序不同的檔案時很有用。

   count(x)

      回傳 *x* 在陣列中出現了幾次。

   extend(iterable)

      從 *iterable* 中新增元素到陣列的尾端，如果 *iterable* 是另一個陣
      列，它必須有完全相同的 type code，如果不同會導致 "TypeError"。如
      果 *iterable* 不是一個陣列，它必須可以被疊代 (iterable) 且其中的
      元素必須是可以被加入陣列中的正確型別。

   frombytes(buffer)

      Appends items from the *bytes-like object*, interpreting its
      content as an array of machine values (as if it had been read
      from a file using the "fromfile()" method).

      在 3.2 版新加入: 將 "fromstring()" 更名為 "frombytes()"，使其更
      加清晰易懂。

   fromfile(f, n)

      從 *file object* *f* 讀取 *n* 個元素（作為機器數值），接著將這些
      元素加入陣列的最尾端。如果只有少於 *n* 個有效的元素會導致
      "EOFError"，但有效的元素仍然會被加入陣列中。

   fromlist(list)

      從 list 中新增元素。這等價於 "for x in list: a.append(x)"，除了
      有型別錯誤產生時，陣列會保持原狀不會被更改。

   fromunicode(s)

      Extends this array with data from the given Unicode string. The
      array must have type code "'u'"; otherwise a "ValueError" is
      raised. Use "array.frombytes(unicodestring.encode(enc))" to
      append Unicode data to an array of some other type.

   index(x[, start[, stop]])

      回傳 *i* 的最小數值，使得 *i* 成為陣列之中第一次出現 *x* 的索引
      。選擇性的引數 *start* 及 *stop* 則可以被用來在指定的陣列空間中
      搜尋 *x*。如果 *x* 不存在將導致 "ValueError"。

      在 3.10 版的變更: 新增選擇性的參數 *start* 及 *stop*。

   insert(i, x)

      在位置 *i* 之前插入一個元素 *x*。負數的索引值會從陣列尾端開始數
      。

   pop([i])

      移除並回傳陣列索引值 *i* 的元素。選擇性的引數 *i* 預設為 "-1"，
      所以預設會刪除並回傳最後一個元素。

   remove(x)

      從陣列中刪除第一個出現的 *x*。

   reverse()

      反轉陣列中元素的順序。

   tobytes()

      將陣列轉為另一個機器數值組成的陣列並回傳它的位元組表示（跟用
      "tofile()" 方法寫入檔案時的位元序列相同）。

      在 3.2 版新加入: 為了明確性，過去的 "tostring()" 已更名為
      "tobytes()"。

   tofile(f)

      將所有元素（作為機器數值）寫入 *file object* *f*。

   tolist()

      不更改元素，將陣列轉為一般的 list。

   tounicode()

      Convert the array to a Unicode string.  The array must have a
      type "'u'"; otherwise a "ValueError" is raised. Use
      "array.tobytes().decode(enc)" to obtain a Unicode string from an
      array of some other type.

The string representation of array objects has the form
"array(typecode, initializer)". The *initializer* is omitted if the
array is empty, otherwise it is a Unicode string if the *typecode* is
"'u'", otherwise it is a list of numbers. The string representation is
guaranteed to be able to be converted back to an array with the same
type and value using "eval()", so long as the "array" class has been
imported using "from array import array". Variables "inf" and "nan"
must also be defined if it contains corresponding floating point
values. Examples:

   array('l')
   array('u', 'hello \u2641')
   array('l', [1, 2, 3, 4, 5])
   array('d', [1.0, 2.0, 3.14, -inf, nan])

也參考:

  "struct" 模組
     將包含不同資料類型的二進位資料包裝與解開包裝。

  "xdrlib" 模組
     將 External Data Representation (XDR) 的資料包裝與解開包裝，這用
     在一些遠端操作的系統 (remote procedure call systems)。

  NumPy
     NumPy 套件定義了另一個陣列型別
