import numpy as np import base64 import zlib import json ## array size ns=2600 # Generate the array of random four-digit integers array = np.random.randint(0, 4000, size=(ns, 1)) # Save the array to a file np.savetxt('integer_array.txt', array, fmt='%d') # Convert the array to binary binary_data = array.flatten().astype('uint16').tobytes() # Compress the binary data using zlib compressed_data = zlib.compress(binary_data) # Convert the compressed data to a base64-encoded binary payload base64_payload = base64.b64encode(compressed_data).decode() # Save the base64-encoded binary payload to a file with open('base64_payload.txt', 'w') as file: file.write(base64_payload) # Create a dictionary with the desired JSON structure json_data = { "req": "note.add", "file": "readings.qo", "payload": base64_payload } # Convert the dictionary to JSON string json_string = json.dumps(json_data, indent=4) # Save the JSON string to a file with open('payload.json', 'w') as file: file.write(json_string) # Decode the base64 payload and decompress it decoded_payload = base64.b64decode(base64_payload) decompressed_data = zlib.decompress(decoded_payload) # Convert the decompressed binary data back to an array of integers decoded_array = np.frombuffer(decompressed_data, dtype='uint16').reshape((ns, 1)) # Save the decoded array to a file np.savetxt('decoded_array.txt', decoded_array, fmt='%d') arrays_equal = np.array_equal(array, decoded_array) if arrays_equal: print("The original array and the decoded array are equal.") else: print("The original array and the decoded array are not equal.")