On Fri, Feb 21, 2020 at 8:52 AM Stephan Hoyer <sho...@gmail.com> wrote: > > On Thu, Feb 20, 2020 at 12:41 PM Steve Jorgensen <ste...@stevej.name> wrote: >> >> Christopher Barker wrote: >> ... >> > > Perhaps the OP wanted the internal array size initialized, but not used. >> > Currently the internal array will automatically be reallocated to grow as >> > needed. Which could be a performance hit if you know it’s going to grow >> > large. >> > But frankly, it would be a rare case where this would be noticeable. >> > -CHB >> >> Maybe uncommon, but I don't know about rare. Let's say you want to perform >> list-wise computations, making new lists with results of operations on >> existing lists (similar to numpy, but maybe trying to do something numpy is >> unsuitable for)? You would want to pre-allocate the new array to the size of >> the operand arrays. > > > Strong +1 for an array.zeros() constructor, and/or a lower level > array.empty() which doesn't pre-fill values. >
So it'd be a shorthand for something like this? >>> array.array("i", bytes(64)) array('i', [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) It'd be convenient to specify the size as a number of array elements rather than bytes. But I'm not a heavy user of array.array() so I won't say either way as to whether this is needed. ChrisA _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/L3SZD4UIKS2BTBG5VLPV3QGI6PLW7EKI/ Code of Conduct: http://python.org/psf/codeofconduct/