python 怎么把byte_array怎么转换为double数组?
时间: 2024-02-03 22:15:39 浏览: 38
你可以使用 struct 模块将 byte array 转换为 double 数组。
以下是一个示例代码:
```python
import struct
# 将 byte array 转换为 double 数组
byte_array = b'\x9a\x99\x99\x99\x99\x99\xb9\x3f\xcd\xcc\xcc\xcc\xcc\xcc\x0c\x40'
double_array = []
for i in range(0, len(byte_array), 8):
double_array.append(struct.unpack('d', byte_array[i:i+8])[0])
print(double_array) # 输出 [1.2, 3.4]
```
在这个示例代码中,我们首先定义了一个 byte array `byte_array`,它包含两个 double 数组的数据。然后我们使用 `struct.unpack` 函数将 byte array 中的每个 8 字节解包为一个 double 数组元素。最后,我们将解包后的 double 数组存储在 `double_array` 中,并打印它的值。