Sep-21-2021, 07:45 PM
(This post was last modified: Sep-21-2021, 07:45 PM by deanhystad.)
Signed? Integers are not sized in Python, so there is no unsigned int type unless you are using numpy or the ctypes library. Array? Python has lists, not arrays. There are Python packages/libraries that support arrays such as numpy or array. Are you using one of those?
If I was using numpy the code might look like this:
If I was using numpy the code might look like this:
import numpy as np def split_and_write(data, channels, filename): '''Split multiplexed time history data into channels and write each channel to own file file''' buffer = np.transpose(data.reshape((-1, channels))) for i, row in enumerate(buffer): row.tofile(f'{filename}{i+1}.bin') data = np.array(range(10*7)) # Create array [0..69] split_and_write(data, 7, 'data') # Creates files data1.bin through data7.binThis splits an array [0..69] into the following arrays and writes them to files
Output:[ 0 7 14 21 28 35 42 49 56 63] -> data1.bin
[ 1 8 15 22 29 36 43 50 57 64] -> data2.bin
[ 2 9 16 23 30 37 44 51 58 65] -> data3.bin
[ 3 10 17 24 31 38 45 52 59 66] -> data4.bin
[ 4 11 18 25 32 39 46 53 60 67] -> data5.bin
[ 5 12 19 26 33 40 47 54 61 68] -> data6.bin
[ 6 13 20 27 34 41 48 55 62 69] -> data7.bin
When I look at a hex dump of the data1.bin I see:Output:00 00 00 00 07 00 00 00 0E 00 00 00 15 00 00 00
1C 00 00 00 23 00 00 00 2A 00 00 00 31 00 00 00
38 00 00 00 3F 00 00 00
Raw binary is not a good way to save information, so if I was writing this file to be processed by a Python program I would save the metadata with the binary information so it could be used on machines with different byte order