[英]IndexError: tuple index out of range while accessing numpy ndarray shape
我正進入(狀態
Index error: Tuple index out of range while doing one-hot encoding for smile string at line:
if ans.shape[1]<length:
例子:
smiles_string= ['C', 'C', '1', '=', 'C', 'C', '(', '=', 'C', 'N', '=', 'C', '1', 'C', '2', '=', 'C', 'C', '(', '=', 'N', 'C', '=', 'C', '2', ')', 'C', ')', 'C', 'C', '(', '=', 'O', ')', 'N', 'C', '3', '=', 'N', 'C', '=', 'C', '(', 'C', '=', 'C', '3', ')', 'C', '4', '=', 'N', 'C', '=', 'C', 'N', '=', 'C', '4']
char_list=['7', '2', '.', 'Br', 'Pt', '=', '[', 'F', '(', ')', 'O', '6', 'S', '5', '1', 'I', ']', '+', '8', '#', 'C', '3', 'B', '9', 'Cl', 'P', '-', '4', 'N']
def onehot_encode(char_list, smiles_string, length):
encode_row = lambda char: map(int, [c == char for c in smiles_string])
print(encode_row)
ans = np.array(map(encode_row, char_list))
if ans.shape[1] < length:
residual = np.zeros((len(char_list), length - ans.shape[1]), dtype=np.int8)
ans = np.concatenate((ans, residual), axis=1)
return ans
我試過調試,發現ans數組的形狀是(),這不應該發生。
如果有人可以提供有關如何映射並解決錯誤的想法,將不勝感激。
先感謝您。
你在沒有形狀的東西上調用.shape()
。
print(ans)
Out[1]: <map object at 0x000001E9352B8908>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.