這裏的適當10-powered
比例縮放每個元素,總結模擬串聯作用後,量化的方法 -
# Calculate each elements number of digits
pows = np.floor(np.log10(dstacker)).astype(int)+1
# 10 powered scalings needed for each elements except the last column
scale = (10**pows[:,:,1:])[:,:,::-1].cumprod(axis=-1)[:,:,::-1]
# Finally get the concatenated number using the scalings and adding last col
num = ((dstacker[:,:,:-1]*scale).sum(-1) + dstacker[:,:,-1]).ravel()
剩餘的工作是寫1D
輸出數組num
到一個文件中。
採樣運行 -
In [7]: dstacker
Out[7]:
array([[[ 1, 27, 13],
[27800, 8, 14]],
[[54543, 559, 5],
[ 4, 10, 17776]],
[[ 5, 11, 17],
[ 6, 2, 18]]])
In [8]: pows = np.floor(np.log10(dstacker)).astype(int)+1
...: scale = (10**pows[:,:,1:])[:,:,::-1].cumprod(axis=-1)[:,:,::-1]
...: num = ((dstacker[:,:,:-1]*scale).sum(-1) + dstacker[:,:,-1]).ravel()
...:
In [9]: num
Out[9]: array([ 12713, 27800814, 545435595, 41017776, 51117, 6218])
這是一個很好的解決方案。當其中一個元素爲零時,有任何解決方法。 (那麼累計總和會給出不正確的值) – akilat90