Lines Matching refs:array
1 :mod:`array` --- Efficient arrays of numeric values
4 .. module:: array
11 This module defines an object type which can compactly represent an array of
54 ``array('u')`` now uses ``wchar_t`` as C type instead of deprecated
68 .. class:: array(typecode[, initializer])
70 A new array whose items are restricted by *typecode*, and initialized
75 If given a list or string, the initializer is passed to the new array's
77 to add initial items to the array. Otherwise, the iterable initializer is
80 .. audit-event:: array.__new__ typecode,initializer array.array
88 value must be an array object with the same type code; in all other cases,
94 .. attribute:: array.typecode
96 The typecode character used to create the array.
99 .. attribute:: array.itemsize
101 The length in bytes of one array item in the internal representation.
104 .. method:: array.append(x)
106 Append a new item with value *x* to the end of the array.
109 .. method:: array.buffer_info()
112 length in elements of the buffer used to hold array's contents. The size of the
113 memory buffer in bytes can be computed as ``array.buffer_info()[1] *
114 array.itemsize``. This is occasionally useful when working with low-level (and
116 :c:func:`ioctl` operations. The returned numbers are valid as long as the array
121 When using array objects from code written in C or C++ (the only way to
123 interface supported by array objects. This method is maintained for backward
128 .. method:: array.byteswap()
130 "Byteswap" all items of the array. This is only supported for values which are
136 .. method:: array.count(x)
138 Return the number of occurrences of *x* in the array.
141 .. method:: array.extend(iterable)
143 Append items from *iterable* to the end of the array. If *iterable* is another
144 array, it must have *exactly* the same type code; if not, :exc:`TypeError` will
145 be raised. If *iterable* is not an array, it must be iterable and its elements
146 must be the right type to be appended to the array.
149 .. method:: array.frombytes(s)
151 Appends items from the string, interpreting the string as an array of machine
158 .. method:: array.fromfile(f, n)
161 them to the end of the array. If less than *n* items are available,
163 inserted into the array.
166 .. method:: array.fromlist(list)
169 a.append(x)`` except that if there is a type error, the array is unchanged.
172 .. method:: array.fromunicode(s)
174 Extends this array with data from the given unicode string. The array must
175 be a type ``'u'`` array; otherwise a :exc:`ValueError` is raised. Use
176 ``array.frombytes(unicodestring.encode(enc))`` to append Unicode data to an
177 array of some other type.
180 .. method:: array.index(x[, start[, stop]])
183 *x* in the array. The optional arguments *start* and *stop* can be
184 specified to search for *x* within a subsection of the array. Raise
190 .. method:: array.insert(i, x)
192 Insert a new item with value *x* in the array before position *i*. Negative
193 values are treated as being relative to the end of the array.
196 .. method:: array.pop([i])
198 Removes the item with the index *i* from the array and returns it. The optional
203 .. method:: array.remove(x)
205 Remove the first occurrence of *x* from the array.
208 .. method:: array.reverse()
210 Reverse the order of the items in the array.
213 .. method:: array.tobytes()
215 Convert the array to an array of machine values and return the bytes
223 .. method:: array.tofile(f)
228 .. method:: array.tolist()
230 Convert the array to an ordinary list with the same items.
233 .. method:: array.tounicode()
235 Convert the array to a unicode string. The array must be a type ``'u'`` array;
236 otherwise a :exc:`ValueError` is raised. Use ``array.tobytes().decode(enc)`` to
237 obtain a unicode string from an array of some other type.
240 When an array object is printed or converted to a string, it is represented as
241 ``array(typecode, initializer)``. The *initializer* is omitted if the array is
244 array with the same type and value using :func:`eval`, so long as the
245 :class:`~array.array` class has been imported using ``from array import array``.
248 array('l')
249 array('u', 'hello \u2641')
250 array('l', [1, 2, 3, 4, 5])
251 array('d', [1.0, 2.0, 3.14])
264 The NumPy package defines another array type.