I have the following code:
import random
import numpy as np
import pandas as pd
num_seq = 100
len_seq = 20
nts = 4
sequences = np.random.choice(nts, size = (num_seq, len_seq), replace=True)
sequences = np.unique(sequences, axis=0) #sorts the sequences
d = {}
pr = 5
for i in range(num_seq):
globals()['seq_' + str(i)] = np.tile(sequences[i,:],(pr,1))
d['seq_' + str(i)] = np.tile(sequences[i,:],(pr,1))
pool = np.empty((0,len_seq),dtype=int)
for i in range(num_seq):
pool = np.concatenate((pool,eval('seq_' +str(i))))
I want to convert the dictionary d into a Numpy array (or a dictionary with just one entry). My code works, producing pool. However, at bigger values for num_seq, len_seq and pr, it takes a very long time.
The execution time is critical, thus my question: is there a more efficient way of doing this?