<p dir="auto">It would be nice to have Generator.integers match the functionality of Generator.random by allowing usage of the <code class="notranslate">out</code> parameter.</p>
<p dir="auto">Use case: Repeatedly generating large arrays of indices, without needing to allocate new memory each time.</p>
<p dir="auto">I encountered a curious performance issue in numpy.dot multiplication of an N-dimensional array with a 2-dimensional array. I consistently found it to be a factor 15-20 faster to first reshape arrays to 2-dimensional arrays, do the multiplication on the reshaped arrays, and then reshape back.</p>
<p dir="auto">I'm including my code at the end of this message. It appears that the same observation has been made by hpaulj and buried in a StackOverflow question: <a href="http://stackoverflow.com/questions/33004551/why-is-b-numpy-dota-x-so-much-slower-looping-through-doing-bi-numpy" rel="nofollow">http://stackoverflow.com/questions/33004551/why-is-b-numpy-dota-x-so-much-slower-looping-through-doing-bi-numpy</a>. I would love to have numpy.dot automatically do the reshaping, it's much more user-friendly.</p>
<p dir="auto">Here is a related post: <a href="https://www.huyng.com/posts/faster-numpy-dot-product" rel="nofollow">https://www.huyng.com/posts/faster-numpy-dot-product</a>. I believe it is better to invoke BLAS through reshaping than the solution proposed there.</p>
<p dir="auto">Thanks!</p>
<p dir="auto">(tested on: numpy 1.12.1 on anaconda with python 3.6.0, mac on intel)</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import numpy as np

n1 = 400
n2 = 50
n3 = 100
n4 = 200

A = np.random.random((n1,n2,n3))
B = np.random.random((n3,n4))

direct = A @ B # result has shape (n1,n2,n4)
indirect = (A.reshape((n1*n2,n3)) @ B).reshape((n1,n2,n4))

np.allclose(direct,indirect) # True

%timeit A @ B
#1 loop, best of 3: 195 ms per loop
%timeit (A.reshape((n1*n2,n3)) @ B).reshape((n1,n2,n4))
#10 loops, best of 3: 27.7 ms per loop

"><pre class="notranslate"><code class="notranslate">import numpy as np

n1 = 400
n2 = 50
n3 = 100
n4 = 200

A = np.random.random((n1,n2,n3))
B = np.random.random((n3,n4))

direct = A @ B # result has shape (n1,n2,n4)
indirect = (A.reshape((n1*n2,n3)) @ B).reshape((n1,n2,n4))

np.allclose(direct,indirect) # True

%timeit A @ B
#1 loop, best of 3: 195 ms per loop
%timeit (A.reshape((n1*n2,n3)) @ B).reshape((n1,n2,n4))
#10 loops, best of 3: 27.7 ms per loop


</code></pre></div>