1. numpy使用中遇到的问题
1. from numpy import array
array(int(l[0]),l[1])
上述语句报错: data type not understood
解决方案:
array((int(l[0]),l[1]))
因为array含有shape参数,可能为一个int,或者一个int sequence 。
numpy.array中的元素均为同一种数据类型。
python中有list可以包含不同数据类型的元素,表示形式为[1,'q']
2. dict的操作
print(titles[123])
上述语句报错:keyError,如果字典中没有相应的key则报错,为了健壮性,采用如下方案。
解决方案:
print(titles.get('123'))
上述方案,如果字典中没有相应的key,则输出:None