I'm trying to convert a 2D-array composed by integers to a big endian binary file using Python by this way:
import struct;
fh=open('file.bin','wb')
for i in range(width):
for j in range(height):
fh.write(struct.pack('>i2',data[i,j]))
fh.close()
when I open it with numpy:
a=np.fromfile('file.bin',dtype='>i2')
The result is an array with zeros between original data:
[266, 0, 267, 0, 268,
0, 272, 0, 268, 0, 264, 0, 266, 0, 264, 0, 263, 0,
263, 0, 267, 0, 263, 0, 265, 0, 266, 0, 266, 0, 267,
0, 267, 0, 266, 0, 265, 0, 270, 0, 270, 0, 270, 0,
272, 0, 273, 0, 275, 0, 274, 0, 275]
That's what I'm trying to obtain:
[266, 267, 268, 272, 268, 264, 266, 264, 263,
263, 267, 263, 265, 266, 266, 267,
267, 266, 265, 270, 270, 270, 272, 273, 275, 274, 275]
Do you know what is wrong with my code?