Pad 0's Of Numpy Array To Nearest Power Of Two
<p><strong>Question:</strong></p>

<p>How to <strong>quickly</strong> add 0's to a large array (~ 600 000 entries) at the beginning to bring the length of the array to the next power of two. (2^n) Is there a faster solution besides np.concatinate()?</p>

<p><strong>What I've already tried:</strong></p>

<ul>
<li>Using the np.concatenate(0, arr) function until the length of the array is equal to the next power of two. The code I have works, it just takes a very very long time. </li>
</ul>

<p><strong>Here's the pad left function:</strong></p>

<pre><code>def PadLeft(arr):
    nextPower = NextPowerOfTwo(len(arr))
    deficit = int(math.pow(2, nextPower) - len(arr))
    #for x in range(1, int(deficit)):
    for x in range(0, deficit):    
        arr = np.concatenate(([0], arr))
    return arr
</code></pre>

<p><strong>Here's the next power of two function:</strong></p>

<pre><code>def NextPowerOfTwo(number):
    # Returns next power of two following 'number'
    return math.ceil(math.log(number,2))
</code></pre>

<p><strong>My implementation:</strong></p>

<pre><code>arr = np.ones(())
a = PadLeft(arr)
</code></pre>

<p>Thanks!</p>