Python 读取GIST Data Set(二)

来源:互联网 发布:电脑网络钓鱼游戏 编辑:程序博客网 时间:2024/05/21 07:07

摘取自:http://www.cnblogs.com/gala/archive/2011/09/22/2184801.html

以读取GIST SIFT数据集为目的对原文进行了摘选和修改:


对struct.unpack_from('<I' , Buffer , index)中重要参数'<I' 进行说明:


struct支持以下格式:

FormatC TypePython字节数xpad byteno value1ccharstring of length 1bsigned charinteger1Bunsigned charinteger1?_Boolbool1hshortinteger2Hunsigned shortinteger2iintinteger4Iunsigned intinteger or long4llonginteger4Lunsigned longlong4qlong longlong8Qunsigned long longlong8ffloatfloat4ddoublefloat8schar[]string1pchar[]string1
对于Matlab中的Uint8数据类型,可以替换为unsigned char.


struct根据本地机器字节顺序转换(Big-endian, Little-endian).可以用格式中的第一个字符来改变对齐方式.

定义如下:

Character

Byte order

Size and alignment

@

native

native          凑够4个字节

=

native

standard       按原字节数

< 

little-endian

standard       按原字节数

> 

big-endian

standard        按原字节数

!

network (= big-endian)

standard        按原字节数


E.g: 

'<IIII'小端方式读入连续16字节,解析为4个Python中4字节整形数据类型.

'>I6f7BI'大端方式读入连续(4+6*4+7*1+4)字节。

解析为连续的1个4字节整形数据类型,6个4字节float数据类型,7个1字节整形数据类型,一个4字节整形数据类型.

0 0
原创粉丝点击