Question:
How to quickly 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()?
What I've already tried:
- 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.
Here's the pad left function:
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
Here's the next power of two function:
def NextPowerOfTwo(number):
# Returns next power of two following 'number'
return math.ceil(math.log(number,2))
My implementation:
arr = np.ones(())
a = PadLeft(arr)
Thanks!