You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Trying to write out an object with a numpy element (ndarray) throws this:
File "/usr/local/lib/python3.7/dist-packages/cbor2/encoder.py", line 428, in dump
CBOREncoder(fp, **kwargs).encode(obj)
File "/usr/local/lib/python3.7/dist-packages/cbor2/encoder.py", line 386, in encode
encoder(self, obj)
File "/usr/local/lib/python3.7/dist-packages/cbor2/encoder.py", line 49, in wrapper
func(encoder, value, *args, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/cbor2/encoder.py", line 107, in encode_array
encoder.encode(item)
File "/usr/local/lib/python3.7/dist-packages/cbor2/encoder.py", line 386, in encode
encoder(self, obj)
File "/usr/local/lib/python3.7/dist-packages/cbor2/encoder.py", line 49, in wrapper
func(encoder, value, *args, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/cbor2/encoder.py", line 115, in encode_map
encoder.encode(val)
File "/usr/local/lib/python3.7/dist-packages/cbor2/encoder.py", line 384, in encode
raise CBOREncodeError('cannot serialize type %s' % obj_type.__name__)
cbor2.encoder.CBOREncodeError: cannot serialize type ndarray
Can this be handled better?
The text was updated successfully, but these errors were encountered:
Unfortunately ndarrays are wrappers around multi-dimensional buffers of C-types so it might be easiest for you to pickle them and save the resulting bytes as a single tagged item than encode them in CBOR.
Alternatively you could serialize them item-by-item as lists of lists of integers. This will be slow on both encode and decode. ndarrays also come with a bunch of metadata that needs to be saved and recreated.
Sekenre
added a commit
to Sekenre/cbor2
that referenced
this issue
Sep 28, 2020
Trying to write out an object with a numpy element (ndarray) throws this:
Can this be handled better?
The text was updated successfully, but these errors were encountered: