[Numpy-discussion] Why does np.repeat build a full array?

Juan Nunez-Iglesias jni.soma at gmail.com
Tue Dec 15 01:49:59 EST 2015


Hi,

I've recently been using the following pattern to create arrays of a
specific repeating value:

from numpy.lib.stride_tricks import as_strided
value = np.ones((1,), dtype=float)
arr = as_strided(value, shape=input_array.shape, strides=(0,))

I can then use arr e.g. to count certain pairs of elements using
sparse.coo_matrix. It occurred to me that numpy might have a similar
function, and found np.repeat. But it seems that repeat actually creates
the full, replicated array, rather than using stride tricks to keep it
small. Is there any reason for this?

Thanks!

Juan.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20151215/d14297c4/attachment.html>


More information about the NumPy-Discussion mailing list