Reading numpy arrays outside of Python

Posted by Abiel on Stack Overflow See other posts from Stack Overflow or by Abiel
Published on 2010-04-27T22:24:09Z Indexed on 2010/04/27 23:23 UTC
Read the original article Hit count: 319

Filed under:
|

In a recent question I asked about the fastest way to convert a large numpy array to a delimited string. My reason for asking was because I wanted to take that plain text string and transmit it (over HTTP for instance) to clients written in other programming languages. A delimited string of numbers is obviously something that any client program can work with easily. However, it was suggested that because string conversion is slow, it would be faster on the Python side to do base64 encoding on the array and send it as binary. This is indeed faster.

My question now is, (1) how can I make sure my encoded numpy array will travel well to clients on different operating systems and different hardware, and (2) how do I decode the binary data on the client side.

For (1), my inclination is to do something like the following

import numpy as np
import base64
x = np.arange(100, dtype=np.float64)
base64.b64encode(x.tostring())

Is there anything else I need to do?

For (2), I would be happy to have an example in any programming language, where the goal is to take the numpy array of floats and turn them into a similar native data structure. Assume we have already done base64 decoding and have a byte array, and that we also know the numpy dtype, dimensions, and any other metadata which will be needed.

Thanks.

© Stack Overflow or respective owner

Related posts about python

Related posts about numpy