小编Pla*_*ush的帖子

Numpy数组列切片产生IndexError:无效索引异常

我使用的是numpy和Python 2.6.6的1.5.1版本.

我正在将二进制文件读入一个numpy数组:

>>> dt = np.dtype('<u4,<i2,<i2,<i2,<i2,<i2,<i2,<i2,<i2,u1,u1,u1,u1')
>>> file_data = np.fromfile(os.path.join(folder,f), dtype=dt)
Run Code Online (Sandbox Code Playgroud)

这很好用.检查结果:

>>> type(file_data)
<type 'numpy.ndarray'>

>>> file_data
array([(3571121L, -54, 103, 1, 50, 48, 469, 588, -10, 0, 102, 0, 0),
   (3571122L, -78, 20, 25, 45, 44, 495, 397, -211, 0, 102, 0, 0),
   (3571123L, -69, -48, 23, 60, 19, 317, -26, -151, 0, 102, 0, 0), ...,
   (3691138L, -53, 52, -2, -11, 76, 988, 288, -101, 1, 102, 0, 0),
   (3691139L, -11, 21, -27, 25, 47, 986, 253, …
Run Code Online (Sandbox Code Playgroud)

numpy

6
推荐指数
1
解决办法
6641
查看次数

标签 统计

numpy ×1