1

I make a web app, the server side is running Python and processes data with numpy. I want to display charts from the numpy data on the browser.

On the server I encode a list of numpy arrays with msgpack_numpy:

import numpy
import msgpack
import msgpack_numpy as m
m.patch()

arr1 = numpy.array([1,2]) # just an example
encoded = msgpack.packb([arr1], use_bin_type=True) # I want to transfer a list of np arrays

Then, I pass the encoded bytes through a SignalR websocket, on the web browser side I get a Uint8Array which looks OK.

Now for deserializing:

import { decode } from '@msgpack/msgpack';
const msgpack = { decode };

var data = decode(buffer);

Before I can continue with transforming the output to a numpy-like array I get the following error message:

The type of key must be string or number but object
4
  • 1
    If I recall correctly, msgpack-numpy makes some non-standard changes to the msgpack format. I have not personally tried this library, but have you tried msgpack-numpy-js on the client side so that your JS understands the non-standard changes? Commented 17 hours ago
  • I didn't know about this library, it is very small so I looked at the source code and the first thing it does for unpacking is to call msgpack.decode , from the msgpack-lite package whereas I use the classic msgpack lib... Will do more checks Commented 10 hours ago
  • Why are you trying to use numpy-like array in JS? What type of array are you sending to your frontend? Does a JSON Array meet your expectations? Im trying to figure out the data type you will use on your frontend to understand what type of conversion should be made. Commented 6 hours ago
  • The server side is Python code. I have a numpy array I want to plot on the frontend. So, I need to pass data from server to browser, and since data can be huge I need binary format, this is why I excluded json or base64. Commented 3 hours ago

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.