**
python 中 np常用操作总结:
**
这篇博客是自己在平常使用的时候遇到的np中函数,可能,挖掘能力有限,目前就使用过以下几个,后面碰到了,还会不断更新!望各位见谅!
np.array():
可以把一个list变成数组
例:
a = [1,2,3,4]
a = np.array(a)
a就变成一个内部成员类型相同的数组
np.max():
求最大值
例:
a = [[1,2,3],[4,5,6],[7,8,9]]
a = np.array(a)
max_a = np.max(a[:,1])
返回的是第一列的最大值。
np.min():
求最小值:
方法同上!
np.sqrt():
求平方根:
例:
result = np.sqrt(5,5)
np.diff():
求差值:
例:
result = np.diff(2,5)
np.cos():
求余弦值:
theta = 90
result = np.cos(theta * np.pi / 180)
np.sin():
求正弦值:
方法同上!
np.savetxt():
保存文件:
例:
res = np.array([1,2,3,4])
np.savetxt("d:/image/shape/circular1.txt",res, fmt="%8.3f %8.3f %8.3f %8.3f")
前面是路径,中间是要保存的变量,后面是格式
np.loadtxt():
加载文件:
例:
a = np.array(np.loadtxt("d:/image/shape/circular1.txt"))