[Numpy-discussion] How to speed up array generating
Kevin Sheppard
kevin.k.sheppard at gmail.com
Sat Jan 9 16:12:13 EST 2021
What about arange and then an integer divide or mod?
Kevin
On Sat, Jan 9, 2021, 20:54 <klark--kent at yandex.ru> wrote:
> np.meshgrid, indexing, reshape
>
> 09.01.2021, 22:30, "Joseph Fox-Rabinovitz" <jfoxrabinovitz at gmail.com>:
>
> What other ways have you tried?
>
> On Sat, Jan 9, 2021 at 2:15 PM <klark--kent at yandex.ru> wrote:
>
> Hello. There is a random 1D array m_0 with size 3000, for example:
>
> m_0 = np.array([0, 1, 2])
>
> I need to generate two 1D arrays:
>
> m_1 = np.array([0, 1, 2, 0, 1, 2, 0, 1, 2])
> m_2 = np.array([0, 0, 0, 1, 1, 1, 2, 2, 2])
>
> Is there faster way to do it than this one:
>
> import numpy as npimport time
> N = 3
> m_0 = np.arange(N)
>
> t = time.time()
> m_1 = np.tile(m_0, N)
> m_2 = np.repeat(m_0, N)
> t = time.time() - t
>
> I tried other ways but they are slower or have the same time. Other NumPy operations in my code 10-100 times faster. Why the repeating an array is so slow? I need 10 times speed up. Thank you for your attantion to my problem.
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at python.org
> https://mail.python.org/mailman/listinfo/numpy-discussion
>
> ,
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at python.org
> https://mail.python.org/mailman/listinfo/numpy-discussion
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at python.org
> https://mail.python.org/mailman/listinfo/numpy-discussion
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.python.org/pipermail/numpy-discussion/attachments/20210109/f885507c/attachment.html>
More information about the NumPy-Discussion
mailing list