def fromfile(file, dtype=None, count=-1, sep=''): # real signature unknown; restored from __doc__"""fromfile(file, dtype=float, count=-1, sep='')Construct an array from data in a text or binary file.#从文本或二进制文件中的数据构造一个数组。A highly efficient way of reading binary data with a known data-type,as well as parsing simply formatted text files.  Data written using the`tofile` method can be read using this function.#一种按二进制格式来读取数据的高效方法,还能解析简单格式化的文本文件。使用`tofile`写入数据的方法可以使用这个函数来读取。Parameters----------file : file or strOpen file object or filename.dtype : data-typeData type of the returned array.For binary files, it is used to determine the size and byte-orderof the items in the file.#对于二进制文件,它用于确定文件中项目的大小和字节顺序。count : intNumber of items to read. ``-1`` means all items (i.e., the completefile).sep : strSeparator between items if file is a text file.Empty ("") separator means the file should be treated as binary.Spaces (" ") in the separator match zero or more whitespace characters.A separator consisting only of spaces must match at least onewhitespace.# 如果文件是一个文本文件,默认使用空格分隔。("")分隔符意味着文件应被视为二进制文件。分隔符中的空格("")匹配零个或多个空白字符。仅由空格组成的分隔符必须至少匹配一个""。See also--------load, savendarray.tofileloadtxt : More flexible way of loading data from a text file.Notes-----Do not rely on the combination of `tofile` and `fromfile` fordata storage, as the binary files generated are are not platformindependent.  In particular, no byte-order or data-type information issaved.  Data can be stored in the platform independent ``.npy`` formatusing `save` and `load` instead.Examples--------Construct an ndarray:>>> dt = np.dtype([('time', [('min', int), ('sec', int)]),...                ('temp', float)])>>> x = np.zeros((1,), dtype=dt)>>> x['time']['min'] = 10; x['temp'] = 98.25>>> xarray([((10, 0), 98.25)],dtype=[('time', [('min', '<i4'), ('sec', '<i4')]), ('temp', '<f8')])Save the raw data to disk:>>> import os>>> fname = os.tmpnam()>>> x.tofile(fname)Read the raw data from disk:>>> np.fromfile(fname, dtype=dt)array([((10, 0), 98.25)],dtype=[('time', [('min', '<i4'), ('sec', '<i4')]), ('temp', '<f8')])The recommended way to store and load data:>>> np.save(fname, x)>>> np.load(fname + '.npy')array([((10, 0), 98.25)],dtype=[('time', [('min', '<i4'), ('sec', '<i4')]), ('temp', '<f8')])"""

tofile()只能保存为二进制文件,且不能保存当前数据的行列信息,文件后缀不影响保存格式,还是二进制。

tofile()保存方法对数据读取有要求,需要手动指定读出来的数据的的dtype,如果指定的格式与保存时的不一致,则读出来的就是错误的数据。

python numpy中fromfile函数的使用相关推荐

  1. Python Numpy中transpose()函数的使用

    在Numpy对矩阵的转置中,我们可以用transpose()函数来处理. 这个函数的运行是非常反常理的,可能会令人陷入思维误区. 假设有这样那个一个三维数组(2*4*2): array ([[[ 0, ...

  2. Python numpy中random函数的使用

    np.random:随机数的生成 np.random.random() import numpy as np c = np.random.random() #生成一个(0,1)之间的随机浮点数 pri ...

  3. pythonreshape函数三个参数_Python Numpy中reshape函数参数-1的含义

    python numpy中reshape函数参数-1的含义,新数组的shape属性应该要与原来数组的一致,即新数组元素数量与原数组元素数量要相等.一个参数为-1时,那么reshape函数会根据另一个参 ...

  4. Python使用numpy中trim_zeros函数去除首尾0值的语法

    Python使用numpy中trim_zeros函数去除首尾0值的语法 目录 Python使用numpy中trim_zeros函数去除首尾0值的语法 #numpy中trim_zeros

  5. python sum函数numpy_解决Numpy中sum函数求和结果维度的问题

    使用Numpy(下面简称np)中的sum函数对某一维度求和时,由于该维度会在求和后变成一个数,所以所得结果的这一维度为空. 比如下面的例子: a = np.array([[1,2,3],[4,5,6] ...

  6. Numpy中sum函数的使用方法(Python自带sum函数)

    Numpy中sum函数(Python自带sum函数)的作用是对元素求和. 无参时,所有全加: axis=0,按列相加: axis=1,按行相加: 下边通过例子来说明其用法: #!/usr/bin/en ...

  7. sum函数python后面很多小数_解决Numpy中sum函数求和结果维度的问题

    使用Numpy(下面简称np)中的sum函数对某一维度求和时,由于该维度会在求和后变成一个数,所以所得结果的这一维度为空. 比如下面的例子: a = np.array([[1,2,3],[4,5,6] ...

  8. python中size的用法.dim_对于numpy中的函数的参数dim的一点理解

    对于numpy中的函数的参数dim的一点理解 经常被dim参数搞混.试着总结了一下.记忆瞬间清晰了 以.max(dim)方法为例: >>> import numpy as np &g ...

  9. python求向量函数的雅可比矩阵_在python Numpy中求向量和矩阵的范数实例

    np.linalg.norm(求范数):linalg=linear(线性)+algebra(代数),norm则表示范数. 函数参数 x_norm=np.linalg.norm(x, ord=None, ...

最新文章

  1. 专访清华AIR院长张亚勤:AI在疫情中很重要,但却很「表面」
  2. GridControl详解(十)BandedGridView
  3. 最保险的函数间数组作为参数值传递与返回方法,用memcpy函数
  4. [云炬创业学笔记]第二章决定成为创业者测试3
  5. 遗传算法各Matlab工具箱简介
  6. Redis系列教程(九):Redis的内存回收原理,及内存过期淘汰策略详解
  7. 用java创建一个单例模式,采用Java实现单例模式
  8. php调用window系统自带的命令,比如计算器
  9. 一道头条算法题,一种不为人知的解法!
  10. MySQL学习笔记十七:复制特性
  11. Java里的阻塞队列
  12. 抓包工具tcpdump的使用总结(持续更新)
  13. STM32/STM8选型手册
  14. python中引用javascript代码块
  15. xp系统屏幕刷新率多少最合适--win7w.com
  16. 极化码 串并行译码的辨别(SC BP SCAN)硬判决和软输出
  17. 基于搜狗平台的微信文章爬虫
  18. ubuntu 改屏幕分辨率命令_ubuntu 修改分辨率为自定义分辨率
  19. 2016年终总结与来年计划
  20. 一文带你读懂何为 macOS App 公证,以及如何自动化实现

热门文章

  1. mysql无法启动(centos7):systemctl status mysqld.service:Can‘t create/write to file
  2. 2020最新最全的全国省市区五级四级三级地址数据库sql下载,excel下载
  3. 【渝粤教育】国家开放大学2018年秋季 8181-21T (1)老年保健按摩 参考试题
  4. Python Day8 字符串练习
  5. Java第二课(多线程,jdbc,io)
  6. 工作小结:端正态度,细心!
  7. 最近16款免费的Wordpress主题
  8. Cocos2dx 2.1.5 孤狼优化整合版V1.1(32位)
  9. HighNewTech:2019年5月4日《巴菲特股东大会》—6小时20多个亮点50多个问答(划重点)
  10. 优派vx2480-hd-pro简评 1080p+24寸+144hz+ips直屏 千元小金刚便宜又大碗?