def __shuffled(self): shuffel_corpus = OrderedDict() shuffe_keys = list(self.__corpus.keys()) np_shuffle(shuffe_keys) for key in shuffe_keys: shuffel_corpus[key] = self.__corpus.get(key) self.__corpus = shuffel_corpus
def randomize_matrix(data, savefig=None): size = len(data) rand_data = copy(data) for d in xrange(size): diag = zip(*[range(d, size), range(size - d)]) rdiag = diag[:] np_shuffle(rdiag) for v in xrange(len(diag)): val = data[diag[v][0]][diag[v][1]] a, b = rdiag[v][0], rdiag[v][1] rand_data[b][a] = rand_data[a][b] = val if savefig: plt.subplot(211) plt.imshow(log2(data), interpolation='none') plt.subplot(212) plt.imshow(log2(rand_data), interpolation='none') plt.savefig(savefig, format='pdf') plt.close('all') return rand_data
def shuffle(array): np_shuffle(array) # Store a copy of the array for the assert mock_context['shuffled_array'] = array.copy()