In [ ]:
# this function code has to be debugged further with matrix dimension matching
import numpy as np
def shuffle_spikes(spikeMat, imgPara):
    [numNeuron, NT]= spikeMat.shape
    fakeSpikes = np.zeros(numNeuron, NT)
    numFramesPerStim = int(round(imgPara['stim_time'] / imgPara['dt']))
    
    for i in range(numNeuron):
        spikeR = spikeTrains[i,:].reshape((numFramesPerStim, imgPara['stimrep']))
        shuffleSpikes = np.zeros(numFramesPerStim, imgPara['stimrep'])
        for t in range(numFramesPerStim):
            # shuffle the spikeMat among 20 trials
            shuffleSpikes[t, :] = spikeR[t, np.random.permutation(imgPara['stimrep'])]
        # generate the fake-shuffled spikes for each specific neuron
        fakeSpikes[i, :] = shuffleSpikes.reshape(( 1, NT))
    
    return fakeSpikes