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.

A use case that came up for me recently is efficiently allocating and
filling an object that satisfies the buffer protocol from C/C++ without
requiring a NumPy dependency. As far as I can tell, there is no easy way to
do this currently.
_______________________________________________
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/CJMX4EVEBLC23SVVVRSQHFZW7QYDBDRQ/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to