3.Python科学计算与数据处理.pptVIP

  • 21
  • 0
  • 约2.81万字
  • 约 98页
  • 2017-05-14 发布于天津
  • 举报
3.Python科学计算与数据处理.ppt

文件存取 使用numpy.savetxt和numpy.loadtxt可以读写1维和2维的数组: * a = np.arange(0,12,0.5).reshape(4,-1) np.savetxt(a.txt, a) # 缺省按%.18e格式保存数据,以空格分隔 np.loadtxt(a.txt) array([[ 0. , 0.5, 1. , 1.5, 2. , 2.5], [ 3. , 3.5, 4. , 4.5, 5. , 5.5], [ 6. , 6.5, 7. , 7.5, 8. , 8.5], [ 9. , 9.5, 10. , 10.5, 11. , 11.5]]) np.savetxt(a.txt, a, fmt=%d, delimiter=,) #改为保存为整数,以逗号分隔 np.loadtxt(“a.txt”,delimiter=“,”) # 读入的时也需要指定逗号分隔 array([[ 0., 0., 1., 1., 2., 2.], [ 3., 3., 4., 4., 5., 5.], [ 6., 6., 7., 7., 8., 8.], [ 9., 9., 10., 10., 11., 11.]]) 文件存取 文件名和文件对象 前面所举的例子都是传递的文件名,也可以传递已经打开的文件对象,例如对于load和s

文档评论(0)

1亿VIP精品文档

相关文档