- 教程
- 介绍
- 环境
- Ndarray 对象(Ndarray Object)
- 数据类型
- 数组属性(Array Attributes)
- 阵列创建例程(Array Creation Routines)
- 来自现有数据的数组(Array from Existing Data)
- 数值范围中的数组(Array From Numerical Ranges)
- 数值范围中的数组(Array From Numerical Ranges)
- 数值范围中的数组(Array From Numerical Ranges)
- 广播(Broadcasting)
- 迭代数组(Iterating Over Array)
- 数组操作(Array Manipulation)
- Binary 运算符
- 字符串函数(String Functions)
- 数学函数(Mathematical Functions)
- 算术运算(Arithmetic Operations)
- 统计函数(Statistical Functions)
- 统计函数(Statistical Functions)
- 字节交换(Byte Swapping)
- 副本和视图(Copies & Views)
- 矩阵库(Matrix Library)
- 线性代数(Linear Algebra)
- Matplotlib(Matplotlib)
- 使用Matplotlib的直方图(Histogram Using Matplotlib)
- I/O with NumPy
- 有用的资源
- reshape
- flat
- flatten
- ravel
- transpose
- ndarray.T
- rollaxis
- swapaxes
- broadcast
- broadcast_to
- expand_dims
- squeeze
- concatenate
- stack
- hstack
- vstack
- split
- hsplit
- vsplit
- resize
- append
- insert
- delete
- unique
- bitwise_and
- bitwise_or
- invert
- left_shift
- right_shift
- add()
- multiply()
- center()
- capitalize()
- title()
- lower()
- upper()
- split()
- splitlines()
- strip()
- join()
- replace()
- decode()
- encode()
- dot
- vdot
- inner
- matmul
- determinant
- solve
- inv
文章来源于网络收集而来,版权归原创者所有,如有侵权请及时联系!
I/O with NumPy
ndarray对象可以保存到磁盘文件并从磁盘文件加载。 可用的IO功能是 -
load()和save()函数处理/ numPy二进制文件(扩展名为npy )
loadtxt()和savetxt()函数处理普通文本文件
NumPy为ndarray对象引入了一种简单的文件格式。 此.npy文件存储在磁盘文件中重建ndarray所需的数据,形状,dtype和其他信息,以便即使文件位于具有不同体系结构的另一台计算机上,也可以正确检索该数组。
numpy.save()
numpy.save()文件将输入数组存储在具有npy扩展名的磁盘文件中。
import numpy as np
a = np.array([1,2,3,4,5])
np.save('outfile',a)
要从outfile.npy重建数组,请使用load()函数。
import numpy as np
b = np.load('outfile.npy')
print b
它将产生以下输出 -
array([1, 2, 3, 4, 5])
save()和load()函数接受另一个布尔参数allow_pickles 。 Python中的pickle用于在保存到磁盘文件或从磁盘文件读取之前序列化和反序列化对象。
savetxt()
以简单文本文件格式存储和检索数组数据是使用savetxt()和loadtxt()函数完成的。
例子 (Example)
import numpy as np
a = np.array([1,2,3,4,5])
np.savetxt('out.txt',a)
b = np.loadtxt('out.txt')
print b
它将产生以下输出 -
[ 1. 2. 3. 4. 5.]
savetxt()和loadtxt()函数接受其他可选参数,如页眉,页脚和分隔符。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论