机器学习笔记(2)
来源:互联网 发布:ubuntu 覆盖安装软件 编辑:程序博客网 时间:2024/06/04 20:03
pickle
pickle.dump(obj, file, [,protocol])
注解:将对象obj保存到文件file中去。
protocol为序列化使用的协议版本,0:ASCII协议,所序列化的对象使用可打印的ASCII码表示;1:老式的二进制协议;2:2.3版本引入的新二进制协议,较以前的更高效。其中协议0和1兼容老版本的python。protocol默认值为0。
file:对象保存到的类文件对象。file必须有write()接口, file可以是一个以’w’方式打开的文件或者一个StringIO对象或者其他任何实现write()接口的对象。如果protocol>=1,文件对象需要是二进制模式打开的。
pickle.load(file)
注解:从file中读取一个字符串,并将它重构为原来的python对象。
file:类文件对象,有read()和readline()接口。
ndimage.imread
scipy.ndimage.imread(fname, flatten=False, mode=None)[source]
Read an image from a file as an array.
Parameters:
fname : str
Image file name, e.g. test.jpg, or a file object.
flatten : bool, optional
If true, convert the output to grey-scale. Default is False.
mode : str, optional
mode to convert image to, e.g. RGB.
Returns:
img_array : ndarray
The different colour bands/channels are stored in the third dimension, such that a grey-image is MxN, an RGB-image MxNx3 and an RGBA-image MxNx4.
Raises:
ImportError
If the Python Imaging Library (PIL) can not be imported.
a=([3.234,34,3.777,6.33])
ndarray 和list的转化
a为python的list类型
将a转化为numpy的array:
np.array(a)
array([ 3.234, 34. , 3.777, 6.33 ])
将a转化为python的list
a.tolist()
ndarray 属性
ndarray.ndim:数组的维数
ndarray.shape:数组每一维的大小
ndarray.size:数组中全部元素的数量
ndarray.dtype:数组中元素的类型(numpy.int32, numpy.int16, and numpy.float64等)
ndarray.itemsize:每个元素占几个字节
np.random.permutation(x)
np.random.permutation(x)
随机排列x,如果x是多维向量,则只排列第一维
参数:
x : int or array_like
If x is an integer, randomly permute np.arange(x). If x is an array, make a copy and shuffle the elements randomly.
Returns:
out : ndarray
Permuted sequence or array range.
>>> np.random.permutation(10)array([1, 7, 4, 3, 0, 9, 2, 5, 8, 6])>>> np.random.permutation([1, 4, 9, 12, 15])array([15, 1, 9, 4, 12])>>> arr = np.arange(9).reshape((3, 3))>>> np.random.permutation(arr)array([[6, 7, 8], [0, 1, 2], [3, 4, 5]])
os.stat
stat 系统调用时用来返回相关文件的系统状态信息的。
可以这么理解,os.stat是将文件的相关属性读出来,然后用stat模块来处理,处理方式有多重,就要看看stat提供了什么了。
看一下stat中有哪些属性:
import os>>> print os.stat("/root/python/zip.py")(33188, 2033080, 26626L, 1, 0, 0, 864, 1297653596, 1275528102, 1292892895)>>> print os.stat("/root/python/zip.py").st_mode #权限模式33188>>> print os.stat("/root/python/zip.py").st_ino #inode number2033080>>> print os.stat("/root/python/zip.py").st_dev #device26626>>> print os.stat("/root/python/zip.py").st_nlink #number of hard links1>>> print os.stat("/root/python/zip.py").st_uid #所有用户的user id0>>> print os.stat("/root/python/zip.py").st_gid #所有用户的group id0>>> print os.stat("/root/python/zip.py").st_size #文件的大小,以位为单位864>>> print os.stat("/root/python/zip.py").st_atime #文件最后访问时间1297653596>>> print os.stat("/root/python/zip.py").st_mtime #文件最后修改时间1275528102>>> print os.stat("/root/python/zip.py").st_ctime #文件创建时间1292892895
注意打乱顺序数据集,使分类结果更可信
- 机器学习笔记(2)
- 机器学习-笔记2
- 机器学习笔记2
- 机器学习(笔记)
- 统计机器方法学习笔记(2)
- 机器学习课程笔记整理(2)
- 《机器学习基石》课程笔记(2)
- 机器学习课程2-笔记
- 斯坦福大学机器学习笔记(2)
- COURSERA机器学习笔记2
- 机器学习笔记(2)-决策树
- 机器学习实战笔记2
- 机器学习课堂笔记2
- 机器学习笔记(2)-决策树
- 机器学习笔记(一)
- 机器学习笔记(二)
- 机器学习笔记(三)
- 机器学习笔记(1)
- Python序列类型相互转换总结
- 社科院专家倪鹏飞:为何说房价不是说越低越好
- EBS 12.2.4 clone with linux 7
- freeradius 配置
- map结构体作为key值的使用
- 机器学习笔记(2)
- win7下载超50mb及上传超30min文件失败
- 克隆虚拟机
- struts2中的constant配置详解
- SQL注入攻击常见方式及测试方法
- Unity自定义UI组件(七)渐变工具、渐变色图片、渐变遮罩
- 超级素数的改进算法
- 摩尔定律与搜索引擎-9
- 13天学习Python心得总结(欢迎各位点评)