假设我有以下仅由 16 位值组成的列表:
[65534, 65535, 0, 1 ...... 65534, 65535, 0 , 1 , 3, 4 ]
我想将其转换为 32 位列表,例如:
[65534, 65535, 65536, 65537 ...... 131070, 131071, 131072 , 131073 , 131075, 131076 ]
这意味着遇到 0 后,值应该增加 2 16 (65536),并且任何大于 1 的差值(例如从 1 到 3)都应保留。
在 Python 中是否有一种有效的方法可以做到这一点?我的数组由数百万个点组成。
编辑 :
我在 julia (https://gist.github.com/ssfrr/7995008)中发现了这一点,它似乎有效。
function unwrap(v, inplace=false)
# currently assuming an array
unwrapped = inplace ? v : copy(v)
for i in 2:length(v)
while unwrapped[i] - unwrapped[i-1] >= pi
unwrapped[i] -= 2^4
end
while unwrapped[i] - unwrapped[i-1] <= -pi
unwrapped[i] += 2^4
end
end
return unwrapped
end
test_v = [15, 0, 1 , 2, 3, 6, 8, 14, 15, 0, 1]
res_v = unwrap(test_v)
给出
11-element Vector{Int64}:
15
16
17
18
19
22
24
30
31
32
33