Python将list中的str类型转为int/double型,解决TypeError: cannot perform reduce with flexible type 报错
对于下面的代码:test_list= ['1','2','3','4']如果求和后会报错TypeError: cannot perform reduce with flexible typeimport numpy as npnp.sum(test_list)解决方法1:list1:list = [int(i) for i in test_list]print(np.sum(list1))解决方法2:array:np.array = np.array(test_list).ast