import numpy as np a = '111111111111111111111111111111111111111' np.set_printoptions(suppress=True) x = np.array(a) b = float(a) print(a) print(x,type(x)) print(b,type(b))
输出结果:

本文介绍如何使用Python的NumPy库将字符串转换为数组及浮点数,并展示了设置打印选项以避免科学计数法的方法。通过具体代码实例,演示了不同类型变量的创建与类型检查。
import numpy as np a = '111111111111111111111111111111111111111' np.set_printoptions(suppress=True) x = np.array(a) b = float(a) print(a) print(x,type(x)) print(b,type(b))
输出结果:

3559
4244
2938

被折叠的 条评论
为什么被折叠?