This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: add array.zeroes
Type: enhancement Stage:
Components: Library (Lib) Versions: Python 3.3
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: alex, ncoghlan, rhettinger, santoso.wijaya
Priority: normal Keywords:

Created on 2011-07-22 18:35 by alex, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (4)
msg140901 - (view) Author: Alex Gaynor (alex) * (Python committer) Date: 2011-07-22 18:35
From python-ideas:

introduce array.zeroes, a new classmethod that provides an alternative constructor, its signature is zeroes(typecode, length), which allows for preallocating an array, with a lower overhead than methods such as array(typecode, [0]) * length, and is more readable (plus consistant with the numpy method of the same name).
msg140905 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2011-07-22 20:55
-1

Array's API much more closely matches that of list than it does numpy's arrays which are profoundly different.  So we should stick the one-way-to-do-it idiom:  array.array('c', '\0') * 100 or array.array('d', [0.0]) * 100.

Also, the current idiom is much more flexible in that it works with any initializer, not just a zero (compare with numpy's ones() constructor for example).
msg141133 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2011-07-26 00:43
Compare however the behaviour of bytes() and bytearray() which support direct zero initialisation of a region of memory by passing an integer to their constructor.
msg141139 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2011-07-26 10:23
Array has been around for a very long time and this functionality has never been requested.  That and the fact that we already have a way to do it (the same way as for lists) is a strong indication that this isn't needed at all.
History
Date User Action Args
2022-04-11 14:57:20adminsetgithub: 56824
2011-07-26 10:23:03rhettingersetstatus: open -> closed
resolution: rejected
messages: + msg141139

versions: + Python 3.3, - Python 3.4
2011-07-26 01:44:54santoso.wijayasetnosy: + santoso.wijaya
2011-07-26 00:43:56ncoghlansetnosy: + ncoghlan
messages: + msg141133
2011-07-22 20:55:15rhettingersetassignee: alex -> rhettinger

messages: + msg140905
nosy: + rhettinger
2011-07-22 18:35:11alexcreate