I have:
- a list of english chars, a to z: char_list
- series of strings
I want to create a numpy matrix where each row correspond to the string at the same row in the series, and each column to the character at the same index in the list.
example:
series: [[ab],[ac],[aa]]
chars = [a,b,c]
result = [[110],[101],[200]]
here is how I do it now:
def create_char_matrix(strings, symbol_list):
mat = np.zeros((strings.shape[0],len(symbol_list)))
for i, line in enumerate(strings):
for c in line:
mat[i,symbol_list.index(c)] += 1
return mat
this is not very fast, considering there is often a better solution than nested for loops.
any ideas about how to accelerate this process?