Hi i am trying to create a matrix mapping of excel cells in Python starting from A1 to ZZ1500000. I tried using numpy matmul but it does not work for char vectors. I had to resort using python lists which are super slow. Is there a more elegant solution to this problem? Here is my code:
<code>row_nums = np.arange(1,200000,1)
row_nums = list(map(str, row_nums))
col_nums = []
set_char_l = []
alphabets = list(string.ascii_uppercase)
#set_char = 'A'
for i in range(1, 703, 26):
if i <= 26:
for item in alphabets:
col_nums.append(item)
elif (i // 26) < 27:
set_char = round(i // 26) - 1
new_char = alphabets[set_char]
set_char_l.append(new_char)
for item in alphabets:
col_nums.append(new_char + item)
cell_nums = []
for col in col_nums:
for row in row_nums:
cell_no = col + row
cell_nums.append(cell_no)
cell_nums = np.array(cell_nums)
cell_nums = cell_nums.reshape(len(row_nums), len(col_nums))
</code>
<code>row_nums = np.arange(1,200000,1)
row_nums = list(map(str, row_nums))
col_nums = []
set_char_l = []
alphabets = list(string.ascii_uppercase)
#set_char = 'A'
for i in range(1, 703, 26):
if i <= 26:
for item in alphabets:
col_nums.append(item)
elif (i // 26) < 27:
set_char = round(i // 26) - 1
new_char = alphabets[set_char]
set_char_l.append(new_char)
for item in alphabets:
col_nums.append(new_char + item)
cell_nums = []
for col in col_nums:
for row in row_nums:
cell_no = col + row
cell_nums.append(cell_no)
cell_nums = np.array(cell_nums)
cell_nums = cell_nums.reshape(len(row_nums), len(col_nums))
</code>
row_nums = np.arange(1,200000,1)
row_nums = list(map(str, row_nums))
col_nums = []
set_char_l = []
alphabets = list(string.ascii_uppercase)
#set_char = 'A'
for i in range(1, 703, 26):
if i <= 26:
for item in alphabets:
col_nums.append(item)
elif (i // 26) < 27:
set_char = round(i // 26) - 1
new_char = alphabets[set_char]
set_char_l.append(new_char)
for item in alphabets:
col_nums.append(new_char + item)
cell_nums = []
for col in col_nums:
for row in row_nums:
cell_no = col + row
cell_nums.append(cell_no)
cell_nums = np.array(cell_nums)
cell_nums = cell_nums.reshape(len(row_nums), len(col_nums))
I’ll be grateful for any help.
<code>cell_nums = np.matmul(row_nums.reshape(-1,1), col_nums)
</code>
<code>cell_nums = np.matmul(row_nums.reshape(-1,1), col_nums)
</code>
cell_nums = np.matmul(row_nums.reshape(-1,1), col_nums)
UFuncTypeError: ufunc ‘matmul’ did not contain a loop with signature matching types (dtype(‘<U6’), dtype(‘<U2’)) -> None
New contributor
Zohaib is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.