홈>
msgpack==0.5.1
와 함께 파이썬 3.6을 사용합니다
그리고
msgpack_numpy==0.4.2
.
dict
를 인코딩 및 디코딩하려고 할 때
,
utf-8
를 사용하여 처리 할 문자열 필요
dict의 키를 바이너리 대신 문자열로 복원합니다.
예 :
import msgpack
d = {'key': None}
binary = msgpack.packb(d)
ret = msgpack.unpackb(binary)
ret.keys()
>>> dict_keys([b'key'])
ret = msgpack.unpackb(binary, encoding='utf-8')
ret.keys()
>>> dict_keys(['key'])
그러나 pyzwyz를 사용할 때
msgpack_numpy
를 통과
encoding='utf-8'
를 제동
디코딩 :
numpy
import numpy as np
import msgpack_numpy as m
m.patch()
d['key'] = np.arange(5)
binary = msgpack.packb(d)
ret = msgpack.unpackb(binary)
ret.keys()
>>> dict_keys([b'key'])
ret[b'key']
>>> array([0, 1, 2, 3, 4])
ret = msgpack.unpackb(binary, encoding='utf-8')
ret.keys()
>>> dict_keys(['key'])
ret['key']
>>> {'data': '\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00', 'kind': '', 'nd': True, 'shape': [5], 'type': '<i8'}
를 인코딩/디코딩 할 수 있습니까
numpy
를 사용하는 배열
dict의 키를 바이너리로 바꾸지 않고?
msgpack
-
답변 # 1
관련 질문
- python - Pandas는 dtypes에서 case가 의미하는 바가 있습니까?
- python - 어떤 numpy 인덱스가 복사이고 어느 것이 뷰입니까?
- 3D numpy 배열을 2 그룹으로 나누기 python
- python - matplotlib 등고선 플롯 채우기
- python - 비용 함수가 상승하는 신경망의 버그
- python runtimeerror - numpy 설치 오류
- python - npangle에서 반환 된 부정확 한 위상
- arrays - python/numpy에서 슬라이싱 할 때 '둘러싸 기'
- python - nparray ([1, "a"])가 21 자의 유니 코드 문자열을 사용하는 이유는 무엇입니까?
- 파이썬 목록에서 2D 배열을 만드는 방법은 무엇입니까?
다른 포장 옵션을 사용하여
use_bin_type=True
를 사용하는 것을 발견했습니다 물건을 포장 할 때 문제가 해결됩니다.