Re: [Numpy-discussion] How to speed up array generating

2021-01-11 Thread D. S. McNeil
As Sebastian said, it's going to take more information about context. It's very unlikely that you actually need these particular arrays-- probably, you're interested in some more important result which you're using these arrays as an intermediate step to obtain. Their structure makes that even mo

Re: [Numpy-discussion] How to speed up array generating

2021-01-09 Thread klark--kent
Thank you but the same time:   import numpy as np    import time    N = 3000    m_0 = np.arange(N)    a = np.ones(N)#= first =    t1 = time.time()    m_1 = np.outer(m_0, a).ravel()    m_2 = np.outer(a, m_0).ravel()    t1 = time.time() - t1#= second ===    t2 = time.time()    m_3

Re: [Numpy-discussion] How to speed up array generating

2021-01-09 Thread V. Armando Sole
I guess the speed up, if any, will be machine dependent, but you can give a try at: import numpy as np import time N = 3000 m_0 = np.arange(N) t = time.time() a = np.ones(N) m_1 = np.outer(m_0, a).ravel() m_2 = np.outer(a, m_0).ravel() t = time.time() - t On 2021-01-09 20:07, klark--k...@yandex.

Re: [Numpy-discussion] How to speed up array generating

2021-01-09 Thread Sebastian Berg
On Sat, 2021-01-09 at 23:45 +0300, klark--k...@yandex.ru wrote: > np.meshgrid, indexing, reshape I would expect e.g. reshape helps if you make use of the fact that this is very clear in 2-D. The other thing is ensuring to use the methods `arr.reshape`, `arr.repeat`, which avoids overheads (some of

Re: [Numpy-discussion] How to speed up array generating

2021-01-09 Thread Kevin Sheppard
Actually I would try a broadcast multiply followed by ravel first. Kevin On Sat, Jan 9, 2021, 21:12 Kevin Sheppard wrote: > What about arange and then an integer divide or mod? > > Kevin > > > On Sat, Jan 9, 2021, 20:54 wrote: > >> np.meshgrid, indexing, reshape >> >> 09.01.2021, 22:30, "Jose

Re: [Numpy-discussion] How to speed up array generating

2021-01-09 Thread Kevin Sheppard
What about arange and then an integer divide or mod? Kevin On Sat, Jan 9, 2021, 20:54 wrote: > np.meshgrid, indexing, reshape > > 09.01.2021, 22:30, "Joseph Fox-Rabinovitz" : > > What other ways have you tried? > > On Sat, Jan 9, 2021 at 2:15 PM wrote: > > Hello. There is a random 1D array m_

Re: [Numpy-discussion] How to speed up array generating

2021-01-09 Thread klark--kent
np.meshgrid, indexing, reshape09.01.2021, 22:30, "Joseph Fox-Rabinovitz" :What other ways have you tried?On Sat, Jan 9, 2021 at 2:15 PM 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

Re: [Numpy-discussion] How to speed up array generating

2021-01-09 Thread Joseph Fox-Rabinovitz
What other ways have you tried? On Sat, Jan 9, 2021 at 2:15 PM 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,

[Numpy-discussion] How to speed up array generating

2021-01-09 Thread klark--kent
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 np import time N = 3 m_0 =