title: Faster implementation for shuffling buckets in a dataset? Python
body: <p>Is there a faster way to implement this?  Each row is about 1024 buckets and it's not as fast as I wish it was..</p>
  
  <p>I'd like to generate quite a lot but it needs a few hours to complete as it is.  It's quite the bottleneck at this point..  Any suggestions or ideas for how to optimize it would be greatly appreciated!</p>
  
  <p>Edit*
  Apologies for not having a minimal working example before.  Now it's posted.  If optimization could be made for Python 2.7 it would be very appreciated.</p>
  
  <pre><code>import math
  import numpy as np
  import copy
  import random
  
  def number_to_move(n):
   l=math.exp(-n)
   k=0
   p=1.0
   while p&gt;l:
           k += 1
           p *= random.random()
   return k-n
  
  
  
  def createShuffledDataset(input_data, shuffle_indexes_dict, shuffle_quantity):
    shuffled = []
  
    for key in shuffle_indexes_dict:
        for values in shuffle_indexes_dict[key]:
            temp_holder = copy.copy(input_data[values[0] - 40: values[1]]) #may need to increase 100 padding
  
            for line in temp_holder:                 
                buckets = range(1,1022)
  
                for bucket in buckets:        
                  bucket_value = line[bucket]
                  proposed_number = number_to_move(bucket_value)
                  moving_amount = abs(proposed_number) if bucket_value - abs(proposed_number) &gt;= 0 else bucket_value
  
                  line[bucket] -= moving_amount
  
                  if proposed_number &gt; 0:
                      line[bucket + 1] += moving_amount
                  else:
                      line[bucket - 1] += moving_amount
  
            shuffled.extend(temp_holder)
  
    return np.array(shuffled)
  
  
  example_data = np.ones((100,1024))
  shuffle_indexes = {"Ranges to Shuffle 1" : [[10,50], [53, 72]]}
  
  shuffle_quantity = 1150
  
  shuffled_data = createShuffledDataset(example_data, shuffle_indexes, 
  shuffle_quantity)
  </code></pre>